2013-12-09 82 views
0

我有兩個表「回憶」和「服務」,我需要他們之間的多對多。 我用流利的NHibernate的映射,但它的名字「servicetorecall」流利NHibernate多對多創建附加表格

  public class Recall : BaseDomain 
{ 
    public virtual string Name { get; set; } 
    public virtual string PersonPosition { get; set; } 
    public virtual string RecallText { get; set; } 


    private ICollection<Service> _services = new List<Service>(); 
    public virtual ICollection<Service> Services 
    { 
     get { return _services; } 
     set { _services = value; } 
    } 
} 

    public class Service : BaseDomain 
{ 
    public virtual string Name { get; set; } 
    public virtual string Url { get; set; } 
    public virtual string ImgPath { get; set; } 
    public virtual string ShortContent { get; set; } 
    public virtual string Content { get; set; } 
    public virtual bool ServiceIsVisible { get; set; } 

    ICollection<Recall> _recalls = new List<Recall>(); 
    public virtual ICollection<Recall> Recalls 
    { 
     get { return _recalls; } 
     set { _recalls = value; } 
    } 
} 

映射創建額外的表:

class RecallMappingOverride : IAutoMappingOverride<Recall> 
{ 
    public void Override(AutoMapping<Recall> mapping) 
    { 
     mapping.Cache.ReadWrite(); 
     mapping.HasManyToMany(q => q.Services).Table(MappingNames.RECALLS_RELATIONS) 
      .ParentKeyColumn(MappingNames.RECALL_ID) 
      .ChildKeyColumn(MappingNames.SERVICE_ID).Inverse().Cascade.All(); 

    } 
} 


public class ServiceMappingOverride : IAutoMappingOverride<Service> 
{ 
    public void Override(AutoMapping<Service> mapping) 
    { 
     mapping.Cache.ReadWrite(); 
     mapping.HasManyToMany(q => q.Recalls).Table(MappingNames.RECALLS_RELATIONS)     .ParentKeyColumn(MappingNames.SERVICE_ID).ChildKeyColumn(MappingNames.RECALL_ID) 
       .Inverse().Cascade.All(); 

    } 
} 

我試圖改變級聯但這並沒有幫助。另外我也和其他實體一樣,並且它正確地運作了什麼類型的魔法呢?

回答

1

如何定義「正確」,你想達到什麼目的? 我從來沒有聽說過任何清理解決方案的多對多關係,其中不是使用數據透視表。


[在你的映射快速一瞥]:只有「多對多」的一個應該是逆

相關問題