使用 NHibernate(使用 FluentNHibernate)和代码就像
using NHCfg = NHibernate.Cfg;
var config = new Configuration().AddMappingsFromAssembly<Entity>();
if (UseSqlCe)
{
config.SetProperty(NHCfg.Environment.Driver, typeof(SqlCeDriver).AssemblyQualifiedName);
config.SetProperty(NHCfg.Environment.Dialect, typeof(SqlCeDialect).AssemblyQualifiedName);
}
else if (UseSqlite)
{
config.SetProperty(NHCfg.Environment.Driver, typeof(Sqlite20Driver).AssemblyQualifiedName);
config.SetProperty(NHCfg.Environment.Dialect, typeof(SqliteDialect).AssemblyQualifiedName);
}
使用 EF,它类似于http://rob.conery.io/2014/02/05/using-entity-framework-6-with-postgresql/,您需要与 MSSqlServer (CE) 建立一些紧密联系,例如:
- 迁移或代码优先创建?仅?为 MSSQL 工作
- 默认架构是“dbo”
我的建议是从你更熟悉的开始。
请注意,我有偏见,但 NHibernate 的一些原因:
在内存中使用 sqlite 轻松测试和
config.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, typeof(SingletonConnectionProvider).AssemblyQualifiedName);
/// <summary>
/// ensures that the same connection is used for all sessions. Useful for in-memory databases like sqlite
/// </summary>
public class SingletonConnectionProvider : DriverConnectionProvider
{
private IDbConnection _theConnection;
public override void CloseConnection(IDbConnection conn)
{
}
public override IDbConnection GetConnection()
{
if (_theConnection == null)
{
_theConnection = base.GetConnection();
}
return _theConnection;
}
}
bioth 数据库的模式创建(SchemaExport 类)
- 使用期货读取批处理