From 8d2b13aaa70bc6a8f521df4eab165caf078c33fa Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Fri, 23 Oct 2020 03:13:09 +0300 Subject: DataStore Improvements. --- .../Tango.DataStore.EF/EFDataStoreCollection.cs | 29 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'Software/Visual_Studio/Tango.DataStore.EF/EFDataStoreCollection.cs') diff --git a/Software/Visual_Studio/Tango.DataStore.EF/EFDataStoreCollection.cs b/Software/Visual_Studio/Tango.DataStore.EF/EFDataStoreCollection.cs index eab6ef377..afec27417 100644 --- a/Software/Visual_Studio/Tango.DataStore.EF/EFDataStoreCollection.cs +++ b/Software/Visual_Studio/Tango.DataStore.EF/EFDataStoreCollection.cs @@ -53,15 +53,30 @@ namespace Tango.DataStore.EF public T Get(string key) { - return (T)Get(key); + return (T)Get(key, null); + } + + public T Get(string key, T defaultValue) + { + return (T)Get(key, (object)defaultValue); } public object Get(string key) { - return GetItem(key).Value; + return Get(key, null); + } + + public object Get(string key, object defaultValue) + { + return GetItem(key, defaultValue).Value; } public IDataStoreItem GetItem(string key) + { + return GetItem(key, null); + } + + public IDataStoreItem GetItem(string key, object defaultValue) { using (var db = ObservablesContext.CreateDefault()) { @@ -69,7 +84,15 @@ namespace Tango.DataStore.EF if (item == null) { - throw new KeyNotFoundException("The specified data store key was not found."); + if (defaultValue == null) + { + throw new KeyNotFoundException("The specified data store key was not found."); + } + else + { + Put(key, defaultValue); + return GetItem(key); + } } return item.ToDataStoreItem(); -- cgit v1.3.1