【发布时间】:2009-08-01 01:42:21
【问题描述】:
好的,我有一个数据库,但里面没有表。我有一些实体类。我正在尝试设置 Fluent NH 以使用自动模式导出进行自动映射。
首先,这是可能的,对吧?
其次,如果是这样,我在这里做错了什么:
private ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2005
.ConnectionString(c => c.Is(@"Data Source=foo;Initial Catalog=bar;Integrated Security=True")))
.Mappings(m => m.AutoMappings.Add(AutoPersistenceModel.MapEntitiesFromAssemblyOf<Employee>()
.Where(t => t.Namespace.Contains("Entities"))))
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
}
private void BuildSchema(Configuration cfg)
{
new SchemaExport(cfg).Create(false, true);
}
我在上面的“.Where”行中收到错误“对象引用未设置为对象的实例”。如果我取出 .Where 条件,我会收到错误消息“不能对 ContainsGenericParameters 为 true 的类型或方法执行后期绑定操作。”
编辑:
一些附加信息:我更改了 .Where 语句以明确概述要包含的实体。 IE。 ".Where(t => t.Name.Contains("Employee")" 等。当我这样做时,我收到一个关于缺少依赖项 (NHibernate.ByteCode.Castle) 的错误。当我解决这个问题时,它工作正常. 我还是不明白为什么这行得通。
【问题讨论】:
标签: c# asp.net sql nhibernate fluent-nhibernate