Nuget包在LCL中使用MongoDB作为ORM LCL.Repositories.MongoDB。您应该将它添加到您的应用程序中。 最好在应用程序的一个独立的程序集(dll)中实现MongoDB,并依赖于这个程序集的包。
如您所知,要使用MongoDB,您应该为您的应用程序定义一个ContextSettings类。下面显示了一个ContextSettings示例:
public class MongoDBRepositoryContextSettings : IMongoDBRepositoryContextSettings
{
#region IMongoDBRepositoryContextSettings Members
public MongoServerSettings ServerSettings
{
get
{
var settings = new MongoServerSettings();
settings.Server = new MongoServerAddress("localhost");
settings.WriteConcern = WriteConcern.Acknowledged;
return settings;
}
}
public MongoDatabaseSettings GetDatabaseSettings(MongoServer server)
{
return new MongoDatabaseSettings();
}
public MapTypeToCollectionNameDelegate MapTypeToCollectionName
{
get { return null; }
}
public string DatabaseName
{
get { return Helper.MongoDB_Database; }
}
#endregion
}
存储库用于从更高的层抽象数据访问。更多信息请参阅存储库文档。
public class RoleRepository : MongoDBRepository<Role>, IRoleRepository
{
public RoleRepository(IRepositoryContext context)
: base(context)
{ }
}
由于LCL与MongoDB进行了内置集成,因此它可以与数据存储实体框架支持。我们的免费启动模板是用来与MongoDB一起工作的,但是您可以修改它们以使用不同的数据存储。