2015-05-12 139 views
1

今天,我们正在开发针对SQL Server CE和Entity Framework 6.13作为ORM(代码优先)的Windows环境的解决方案。然而,我们正在研究将它移植到Linux环境的可用性,当然,由于Linux不支持SQL Server数据库,我们打算在Linux机器上使用SQLite,并在Windows机器上继续使用SQL Server。对于这两种环境,解决方案(.sln)都是相同的。具有多个数据库服务器的实体框架

因此,有可能有一个实体框架模型连接多个数据库(SQLServer,SQLite,..)?我应该为每个数据库创建一个模型吗?

对于这种情况,NHibernate是比Entity Framework更好的解决方案吗?或者还有其他什么?

我已经找到了一些有关这方面的答案,但最近没有人。 Ps:代码第一是没有必要的,如果需要,我们打开它来改变它。

非常感谢! :-)使用NHibernate(带FluentNHibernate)和代码

回答

1

它会像

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,你需要对一些紧密联系MSSQLSERVER(CE),如打这将是类似于http://rob.conery.io/2014/02/05/using-entity-framework-6-with-postgresql/

  • 迁移或代码优先创建?对于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; 
        } 
    } 
    
  • schemacreation为bioth数据库(SchemaExport工具类)

  • 读使用期货的配料