【发布时间】:2011-04-07 18:27:53
【问题描述】:
使用 Microsoft 的实体框架设计器 (v3.5),我创建了一个实体模型 (*.edmx),并生成了 *.Designer.cs 类。我可以使用该模型将我的对象持久保存到 MS SQL Server,而不会出现任何问题。
我是 NHibernate 的新手,出于好奇,我现在想将我的模型与 Fluent NHibernate 和 SQLite 一起用作数据库。我已经阅读了Auto mapping article on the Fluent NHibernate wiki。我确实调整了Examples.FirstAutomappedProject 并调整了ExampleAutomappingConfiguration 来映射我的实体。 (我只使用了ShouldMap 和IsId 覆盖)。我的实体相当简单,并且在模型中不包含对彼此的显式引用。
现在,当我构建会话工厂时,出现以下异常:
An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
消息有内部异常
An association from the table XXX refers to an unmapped class: System.Data.EntityKey
我的实体的所有属性都不是System.Data.EntityKey 类型。
[global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName="MyStorageModel", Name="XXX")]
[global::System.Runtime.Serialization.DataContractAttribute(IsReference=true)]
[global::System.Serializable()]
public partial class XXX: global::System.Data.Objects.DataClasses.EntityObject
{
//...
[global::System.Data.Objects.DataClasses.EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
[global::System.Runtime.Serialization.DataMemberAttribute()]
public global::System.Guid XXXID
{
//...
}
//...
}
如您所见,我的实体类被大量装饰(当然是由使用过的设计师),其属性可能引用了这种类型。 这会导致这些麻烦吗?
【问题讨论】:
-
您是否尝试过使用流畅的映射而不是自动映射?您应该能够选择您要映射的内容和不想映射的内容。
标签: nhibernate entity-framework fluent-nhibernate model mapping