0

我有一个复杂的实体,有两个一对多的集合,我想更新它们我该怎么做?

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");
    }
}

实际上它忽略了我的更新,我做错了什么?

4

1 回答 1

0

这是一个奇怪的映射。多对多映射时,关系表(LeadsT​​oActivities)由NH管理,不需要再次映射为实体。

您在 C# 中实际实现的是使用多对多映射的 LeadsT​​oActivities 的一对多集合(它创建了另一个关系表)。

于 2013-11-14T12:34:00.270 回答