我有一个复杂的实体,有两个集合,一对多, 我想更新它们我该怎么办?
Here is my mapping:
internal sealed class LeadMap : ClassMap<Lead> {
public LeadMap() {
Id(x => x.Id).GeneratedBy.Identity().Column("Id");
Map(x => x.Notes, "Notes");
Map(x => x.Source, "Source");
Map(x => x.BusinessName, "BusinessName");
Map(x => x.Telephone, "Telephone");
Map(x => x.UpdateDate, "UpdateDate");
Map(x => x.ConversationDate, "ConversationDate");
Map(x => x.IsConverted, "IsConverted");
Map(x => x.InsertDate, "InsertDate").Generated.Insert();
// contact details mapping
Component(x => x.ContactDetails, contact => {
contact.Map(x => x.Name, "ContactName");
contact.Map(x => x.Email, "ContactEmail");
contact.Map(x => x.Telephone, "ContactTelephone");
});
// City: 1 : 1
References(x => x.City).LazyLoad().Column("CityId");
// MeetingEvent: 1 : 1
References(x => x.MeetingEvent).LazyLoad().Column("MeetingEventId").Cascade.All();
// Agent: 1 : 1
References(x => x.Agent).LazyLoad().Column("AgentId");
// AutoStatus: 1 : 1
References(x => x.AutoStatus).LazyLoad().Column("AutoStatusId");
// ManagementStatus: 1 : 1
References(x => x.ManagementStatus).LazyLoad().Column("ManagementStatusId").Cascade.All();
// Activities: * : *
HasManyToMany(x => x.Activities)
.Cascade
.All()
.LazyLoad()
.NotFound.Ignore()
.ParentKeyColumn("LeadId")
.ChildKeyColumn("ActivityId")
.Table("LeadsToActivities");
// Areas: * : *
HasManyToMany(x => x.Areas)
.Cascade
.All()
.LazyLoad()
.NotFound.Ignore()
.ParentKeyColumn("LeadId")
.ChildKeyColumn("AreaId")
.Table("LeadToAreas");
Table("Leads");
}
}
public sealed class LeadsToActivitiesMap : ClassMap<LeadsToActivities> {
public LeadsToActivitiesMap() {
Id(x => x.Id).GeneratedBy.Identity().Column("Id");
Map(x => x.ActivityId, "ActivityId");
Map(x => x.LeadId, "LeadId");
Table("LeadsToActivities");
}
}
public sealed class AreasToLeadsMap : ClassMap<AreasToLeads> {
public AreasToLeadsMap() {
Id(x => x.Id).GeneratedBy.Identity().Column("Id");
Map(x => x.AreaId, "AreaId");
Map(x => x.LeadId, "LeadId");
Table("LeadToAreas");
}
}
实际上它忽略了我的更新,我做错了什么?
答案 0 :(得分:0)
这是一个奇怪的映射。当映射多对多时,关系表(LeadsToActivities)由NH管理,不需要再次映射为实体。
您在C#中实际实现的是使用多对多(创建另一个关系表)映射的LeadsToActivities的一对多集合。