【发布时间】:2013-03-26 12:11:00
【问题描述】:
当我通过此代码使用 Nhibernate 为 SQL Server CE 创建架构时:
Fluently.Configure()
.Database(MsSqlCeConfiguration.Standard
.ConnectionString(c => c.Is("Data Source=" + file))
.Dialect<NHibernate.Dialect.MsSqlCeDialect>()
.Driver<NHibernate.Driver.SqlServerCeDriver>()
.ShowSql())
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<NHibernateSessionFactory>())
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
private static void BuildSchema(Configuration config)
{
// new SchemaExport(config).Drop(false, true);
//new SchemaExport(config).Create(true, true);
//If DB File does not exists, create it.
if (!File.Exists(file))
{
Directory.CreateDirectory(Path.GetDirectoryName(databaseFileName));
SqlCeEngine engine = new SqlCeEngine("Data Source="+ file);
engine.CreateDatabase();
// this NHibernate tool takes a configuration (with mapping info in)
// and exports a database schema from it
new SchemaExport(config).Execute(false, true, false);
//FormulasDAO.AddDefaultFormulaCollection();
}
else
{
new SchemaUpdate(config).Execute(false, true);
}
}
我遇到了这样的异常
创建 SessionFactory 时使用了无效或不完整的配置。查看PotentialReasons 集合和InnerException 了解更多详情。
内部异常是
程序集中的 IDbCommand 和 IDbConnection 实现 找不到 System.Data.SqlServerCe。确保 程序集 System.Data.SqlServerCe 位于应用程序中 目录或全局程序集缓存中。如果装配在 GAC,在应用程序中使用元素 配置文件来指定程序集的全名。
帮助解决这个问题。
【问题讨论】:
-
异常信息非常清楚。您是否尝试过按照它的指示进行操作?发生了什么?
-
是的,我在 GAC 中检查过,System.Data.SqlServerCe.dll 在那里,我将复制本地设置为这个 dll 引用,没有用。
标签: c# nhibernate fluent-nhibernate sql-server-ce