// Helper method private void SetupAssertEvents(Entity <long, SampleData> entity, IDiffstore <long, SampleData> db) { db.OnSave += (sender, saved) => { Assert.Equal(db, sender); Assert.Equal(entity, saved); }; db.OnDelete += (sender, key) => { Assert.Equal(db, sender); Assert.Equal(key, entity.Key); }; }
/// <summary> /// Checks if this entity exists in the specified storage. /// </summary> /// <param name="db">Storage to be checked.</param> public static bool ExistsIn <TK, TV>(this Entity <TK, TV> entity, IDiffstore <TK, TV> db) where TK : IComparable where TV : class, new() => db.Exists(entity.Key);
/// <summary> /// Deletes this entity from the specified storage. /// </summary> /// <param name="db">Storage in which the entity should be deleted.</param> public static void DeleteFrom <TK, TV>(this Entity <TK, TV> entity, IDiffstore <TK, TV> db) where TK : IComparable where TV : class, new() => db.Delete(entity);
/// <summary> /// Saves this entity in the specified storage. /// </summary> /// <param name="db">Storage in which the entity should be saved.</param> /// <param name="makeSnapshot">If true, creates a snapshot if entity was changed.</param> public static void SaveIn <TK, TV>(this Entity <TK, TV> entity, IDiffstore <TK, TV> db, bool makeSnapshot = true) where TK : IComparable where TV : class, new() => db.Save(entity, makeSnapshot);
/// <summary> /// Creates an embedded (local storage) Diffstore DBMS instance. /// </summary> /// <param name="db">Existing Diffstore instance</param> /// <param name="provider">ITransactionProvider</param> /// <param name="policy">Transaction policy options</param> public static IDiffstoreDBMS <TKey, TValue> Embedded <TKey, TValue>( IDiffstore <TKey, TValue> db, ITransactionProvider <TKey> provider, TransactionPolicyInfo policy) where TKey : IComparable where TValue : class, new() => new EmbeddedDBMS <TKey, TValue>(db, policy, provider);