0

나는 4 개 아래 표 정의 :유창함 NHibernate에 - 조회 테이블에 참조가 테이블에 매핑하는 방법

Projects: 
    Project_Id 
    Project_Name 

Vendors: 
    Vendor_Id 
    Vendor_Name 

Project_Vendors: 
    Project_Vendor_Id 
    Project_Id 
    Vendor_Id 

Project_Vendor_Payments: 
    Payment_Id 
    Project_Vendor_Id 
    Payment_Amount 

내가 유창함 NHibernate에 함께 작동하도록 내 클래스를 정의하기에도 시작할 경우 확실하지 않다 내 매핑을 정의 할 필요는 없습니다.

프로젝트에는 여러 공급 업체가 관련 될 수 있으며 공급 업체는 프로젝트 당 많은 지불을받을 수 있습니다.

내가 어떻게 이런 일이 일어날 수 있는지에 대한 아이디어가 있습니까?

답변

4

내 조회 테이블을 참조하지 않고 엔티티를 직접 참조하는 외래 키 열을 갖는 대신이 문제를 해결했습니다.

Projects: 
    Project_Id 
    Project_Name 

Vendors: 
    Vendor_Id 
    Vendor_Name 

Project_Vendors: 
    Project_Vendor_Id 
    Project_Id 
    Vendor_Id 

Project_Vendor_Payments: 
    Payment_Id 
    Project_Id 
    Vendor_Id 
    Payment_Amount 

내 클래스

과 같이 정의된다 :

public class Project 
{ 
    public virtual int Id { get; set; } 
    public virtual string Name { get; set; } 
    public virtual IList<Vendor> Vendors { get; set; } 
    public virtual IList<VendorPayment> VendorPayments { get; set; } 
} 

public class Vendor 
{ 
    public virtual int Id { get; set; } 
    public virtual string Name { get; set; } 
} 

public class VendorPayment 
{ 
    public virtual int Id { get; set; } 
    public virtual Vendor Vendor { get; set; } 
    public virtual float Amount { get; set; } 
} 

그리고 내 매핑 : 여기

내 테이블 구조

public ProjectMappings : ClassMap<Project> 
{ 
    public ProjectMappings() 
    { 
     Table("Projects"); 
     Id(x => x.Id).Column("Project_Id"); 
     HasManyToMany(x => x.Vendors).Table("Project_Vendors") 
      .ParentKeyColumn("Project_Id") 
      .ChildKeyColumn("Vendor_Id") 
      .Cascade.AllDeleteOrphan(); 
     HasMany(x => x.VendorPayments).Table("Project_Vendor_Payments") 
      .KeyColumn("Project_Id") 
      .Cascade.AllDeleteOrphan(); 
     Map(x => x.Name).Column("Project_Name") 
    } 
} 

public class VendorMappings : ClassMap<Vendor> 
{ 
    public VendorMappings() 
    { 
     Table("Vendors"); 
     Id(x => x.Id).Column("Vendor_Id"); 
     Map(x => x.Name).Column("Vendor_Name"); 
    } 
} 

public class VendorPaymentMappings : ClassMap<VendorPayment> 
{ 
    public VendorPaymentMappings() 
    { 
     Table("Project_Vendor_Payments"); 
     Id(x => x.Id).Column("Payment_Id"); 
     References(x => x.Vendor).Column("Vendor_Id"); 
     Map(x => x.Amount).Column("Payment_Amount"); 
    } 
} 

이에 대한 정확한 답변을하지 않습니다 내 문제가 아니라 오히려 문제의 해결책입니다. 질문에 정확히 무엇을 할 지 여전히 찾고 있습니다.

관련 문제