【发布时间】:2013-07-24 19:05:06
【问题描述】:
我有 Customer 和 Profile 类,其中一个客户可以有多个配置文件。
我正在使用以下 NHibernate 覆盖类:
public void Override(AutoMapping<Customer> mapping)
{
mapping.Table("[Customer]");
mapping.Id(x => x.Id, "Id").GeneratedBy.Identity();
mapping.HasMany(x => x.Profiles).Cascade.All().Inverse();
mapping.Map(x => x.FirstName, "FirstName");
mapping.Map(x => x.LastName, "LastName");
mapping.Map(x => x.Email, "Email");
}
public void Override(AutoMapping<Profile> mapping)
{
mapping.Table("[Profile]");
mapping.Id(x => x.Id, "Id").GeneratedBy.Identity();
mapping.References(x => x.Customer, "Customer_Id").Cascade.None();
mapping.Map(x => x.FacebookProfileLink, "FacebookProfileLink");
mapping.Map(x => x.ContactPhone, "ContactPhone");
}
插入Profile 对象时出现以下错误:
无法将值 NULL 插入到列“Customer_Id”、表“dbo.Profile”中;列不允许空值。 INSERT 失败。\r\n语句已终止。
我的意图是在需要引用Customer 的Profile 之前插入Customer 对象
目的。这就是我使用 Inverse 属性的原因。不幸的是,它不起作用。对此有什么帮助吗?谢谢。
【问题讨论】:
标签: nhibernate one-to-many inverse