我是 NHibernate 用户,NHibernate 允许我创建一个非常细粒度的模型。我正在将应用程序从 NHibernate 移植到实体框架。
NHibernate 允许我定义如下内容:
public class User : DomainEntity
{
public virtual Name Name { get; set; }
...
public virtual ICollection<LogonInformation> LogonInformations { get; set; }
}
public class Name
{
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
}
public class LogonInformation
{
public virtual string Ip { get; set; }
public virtual DateTime Date { get; set; }
}
其中 Name 和 LogonInformation 映射为 <componentes>。在特殊情况下,NHibernate 在创建数据库时,会在 LogonInformation 表中创建 UserId。如何使用 EntityFramework 5 做到这一点?我试过使用复杂类型,但它似乎不起作用,因为我仍然得到以下异常:
在模型生成期间检测到一个或多个验证错误:
\tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'LogonInformation' 没有定义键。定义此 EntityType 的键。
\tSystem.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'LogonInformations' 基于没有定义键的类型'LogonInformation'。