Class DbContext
Describes a MongoDB database: its name and the collections that hold each entity type.
public abstract class DbContext
- Inheritance
-
DbContext
- Inherited Members
Examples
public class ShopContext : DbContext
{
protected override void OnConfiguring(DbContextBuilder context)
{
context.MapCollection("orders").With<Order>();
}
}
Remarks
There is one context per database. Derive from it and map the collections in OnConfiguring(DbContextBuilder), then register it with
AddMongoDatabase<TContext>; use IMongoClientFactory<TContext> to reach the collections.
Properties
DatabaseName
Gets the name of the database, taken from the connection string or from the name given at registration.
public string DatabaseName { get; }
Property Value
EntityCollectionTypes
Gets, for each entity type, the names of the collections it is mapped to.
public Dictionary<Type, List<string>> EntityCollectionTypes { get; }
Property Value
- Dictionary<Type, List<string>>
Methods
OnConfiguring(DbContextBuilder)
Maps the collections of the database.
protected abstract void OnConfiguring(DbContextBuilder context)
Parameters
contextDbContextBuilderThe builder used to map an entity type to a collection.