diff options
Diffstat (limited to 'Software/Visual_Studio/Tango.DataStore.EF/EFDataStoreCollection.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.DataStore.EF/EFDataStoreCollection.cs | 29 |
1 files changed, 26 insertions, 3 deletions
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,23 +53,46 @@ namespace Tango.DataStore.EF public T Get<T>(string key) { - return (T)Get(key); + return (T)Get(key, null); + } + + public T Get<T>(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()) { var item = db.DataStoreItems.SingleOrDefault(x => x.CollectionName == Name && x.Key == key); 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(); |
