/// <summary> /// Gets the IMongoDatabase for the given entity type /// </summary> /// <typeparam name="T">The type of entity</typeparam> public static IMongoDatabase Database <T>(this T _) where T : IEntity => DB.Database <T>();
/// <summary> /// Instantiates and begins a transaction. /// </summary> /// <param name="database">The name of the database to use for this transaction. default db is used if not specified</param> /// <param name="options">Client session options for this transaction</param> public Transaction(string database = default, ClientSessionOptions options = null) { client = DB.Database(database).Client; Session = client.StartSession(options); Session.StartTransaction(); }
/// <summary> /// Instantiates and begins a transaction. /// </summary> /// <param name="database">The name of the database to use for this transaction. default db is used if not specified</param> /// <param name="options">Client session options for this transaction</param> /// <param name="modifiedBy">An optional ModifiedBy instance. /// When supplied, all save/update operations performed via this DBContext instance will set the value on entities that has a property of type ModifiedBy. /// You can inherit from the ModifiedBy class and add your own properties to it. /// Only one ModifiedBy property is allowed on a single entity type.</param> public Transaction(string database = default, ClientSessionOptions options = null, ModifiedBy modifiedBy = null) { Session = DB.Database(database).Client.StartSession(options); Session.StartTransaction(); ModifiedBy = modifiedBy; }