Zoli
Most efficient way to modify json in C#
Probably you missunderstand I am not calling network call from getter and setter.
I am using firebase realtime database
It has this FirebaseOption to be able to configure how to deal when there is no internet. So when i save an item I call
string key = _realtimeDb.Post(item);
and automatically whats to cach to locally as well.
By default it used in memory IDictinory but with that if i restart the app obviously it clears up, so therefore I decided to use LiteDb which is file based offline db for .net.
So in my case when the user logs in first time it pulls all the data and save offline into lite db. later if i do crud even in online/offline mode via _realtimeDb.Post(item);
if there is internet automatically sycns there if no it stores only offline and once it goes online again it syncs the delta from offline -> online.
I agree it should not be set/get when i am reaching Db but as you can see it is predefined for get and set but i do not know how could my setter/gett be replaced if the func requires that. So therefore I implement LiteDb similar to IDic. Of course I am open for improvement for not using getter and setting in case, but no idea.
public OfflineEntry this[string key]
{
get => _db.GetCollection<OfflineEntry>(_collectionName).FindById(key);
set => _db.GetCollection<OfflineEntry>(_collectionName).Upsert(key, value);
}
44 replies
Most efficient way to modify json in C#
So to set Key as part of the Data I wanted
- check if Data is valid json (it triggers with null if delete operation)
- check if Data has key property
- set key property as the outer key
- store in local lite db
44 replies
Most efficient way to modify json in C#
OfflineEntry is a given class, which keeps the state of the syncable Data. This class has Key and Data properties both as string. In the example by default key is not part of the Data and when I call realtime.Get method I only get back all the Data as IEnumerable<T>. So if I want to delete one of them unfortunatelly IEnumerable<T> T Data does not contain the Key itself.
So therefore my idea was when initially filling this IDictionary up I set the key also as a property of the Data. So later when I do crud operation in my repository I can easily.
44 replies
Most efficient way to modify json in C#
I did not want to go deeper in that, but I am using firebase realtime database that one has a Func which
public Func<Type, string, IDictionary<string, OfflineEntry>> OfflineDatabaseFactory { get; set; }
When user opens the app first time it pulls all data from online it stores in local db (by default it stores in memory but i want to reach the data even if next time the app is opened offline).
So I created a LiteDbOfflineDictionary : IDictionary<string, OfflineEntry>
with this when first time all data pulled it stores offline and if any data is changed automatically synces to online.44 replies
Why deletion of last character in Entry not triggers observableProperty? (MVVM, Maui)
Originally I had int?, but with that also was the same case. I changed to string and add a parser with that when the last "number" is deleted it triggers as expected.
4 replies
How to Properly Synchronize ViewModel and Model in MVVM (CommunityToolkit.Mvvm)
Yes, I cache the model when any changes happens automatically. One more thing if you dont mind, with the reactive approach I need to move more logic from viewmodels to models. In this case is model still okay to use as entity for crud operations on local db?
Because I did not have any logic basically in my models previously, now I am moving all (at least what is really for the model) and it became kind of rich models and I was wondering can or is it still good practice to use that for crud operation with local db.
15 replies
How to Properly Synchronize ViewModel and Model in MVVM (CommunityToolkit.Mvvm)
In a reactive approach for an edit operation, FooModel is passed to FooViewModel via the constructor. However, this means that any modifications made in the ViewModel will be directly reflected in the original model, even if the user cancels the operation without saving.
How can I ensure that changes are only applied to the original model after a successful save operation while still leveraging reactivity? What is the best practice for maintaining the original state if the user decides to discard the changes?
15 replies
✅ UNIQUE constraint failed
Ohhh looks good thanks a lot 🍻
Probably it will solve my issue. One more question if you dont mind. I have the ExerciseVariant table which is kind of metadata so only read only.
Do I need this list of exercise at all?
Each exercise can have one exercise variant, and exercise variant can be used for multiple exercise
21 replies