流畅的NHibernate无法使用SQLCE创建会话工厂

时间:2010-11-29 06:44:06

标签: nhibernate fluent-nhibernate

我正在尝试使用Fluent NHibernate完成我的第一个项目(任何NHibernate风格)。当我遇到以下异常时,我无法超越创建会话工厂对象的程度:

InnerException: NHibernate.HibernateException
                      Message=The IDbCommand and IDbConnection implementation in the assembly System.Data.SqlServerCe could not be found. Ensure that the assembly System.Data.SqlServerCe is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use <qualifyAssembly/> element in the application configuration file to specify the full name of the assembly.
                      Source=NHibernate
                      StackTrace:
                           at NHibernate.Driver.ReflectionBasedDriver..ctor(String driverAssemblyName, String connectionTypeName, String commandTypeName)
                           at NHibernate.Driver.SqlServerCeDriver..ctor()
                      InnerException: 

我正在使用最新的FluentNHibernate二进制文件。 VS 2010,在Window 7 x64上。我已将System.Data.SqlServerCe程序集设置为“Copy Local”,将项目的目标平台更改为x86。

流畅的配置是:

var config  = Fluently.Configure()
                        .Database(MsSqlCeConfiguration.Standard.ShowSql().ConnectionString(cnxString))
                        .Mappings(m => m.FluentMappings.AddFromAssemblyOf<SyncContract>());

if (!File.Exists(dbPath))
{
     var engine = new System.Data.SqlServerCe.SqlCeEngine(cnxString);
     engine.CreateDatabase();

     config.ExposeConfiguration(c => new SchemaExport(c).Create(false, true));
}
return config;

注意:engine.CreateDatabase()工作正常。

有任何帮助/想法吗?

1 个答案:

答案 0 :(得分:7)

好的,想通了。

Copy Local不适用于我正在使用的测试项目,因此,libs没有被复制到测试项目的bin文件夹中。添加了所有库作为测试项目的引用,并在其上设置了本地复制以使其工作。