我一直坐在这里一个小时试图解决这个问题......
我有2个表(缩写):
CREATE TABLE TRUST ( TRUSTID NUMBER NOT NULL, ACCTNBR VARCHAR(25) NOT NULL ) CONSTRAINT TRUST_PK PRIMARY KEY (TRUSTID) CREATE TABLE ACCOUNTHISTORY ( ID NUMBER NOT NULL, ACCOUNTNUMBER VARCHAR(25) NOT NULL, TRANSAMT NUMBER(38,2) NOT NULL POSTINGDATE DATE NOT NULL ) CONSTRAINT ACCOUNTHISTORY_PK PRIMARY KEY (ID)
我有2个类基本上反映了这些:
public class Trust { public virtual int Id {get; set;} public virtual string AccountNumber { get; set; } } public class AccountHistory { public virtual int Id { get; set; } public virtual Trust Trust {get; set;} public virtual DateTime PostingDate { get; set; } public virtual decimal IncomeAmount { get; set; }
}
如何在FluentNHibernate中执行多对一映射以使AccountHistory具有信任?具体来说,由于它与TRUSTID的Trust主键不同,并且它所引用的列的名称也不同(ACCTNBR与ACCOUNTNUMBER).这是我到目前为止 - 我如何在AccountHistoryMap上做引用信任?
public class TrustMap : ClassMap{ public TrustMap() { Table("TRUST"); Id(x => x.Id).Column("TRUSTID"); Map(x => x.AccountNumber).Column("ACCTNBR"); } } public class AccountHistoryMap : ClassMap { public AccountHistoryMap() { Table("TRUSTACCTGHISTORY"); Id (x=>x.Id).Column("ID"); References (x => x.Trust).Column("ACCOUNTNUMBER").ForeignKey("ACCTNBR").Fetch.Join(); Map(x => x.PostingDate).Column("POSTINGDATE"); );
我已经尝试了上述几行的一些不同变体,但无法获得任何工作 - 它会回收AccountHistory数据和Trust的代理; 但它没有给出具有给定标识符的Trust行.
这必须简单.任何人?
提前致谢.
你需要使用property-ref:
public class AccountHistoryMap : ClassMap{ public AccountHistoryMap() { Table("TRUSTACCTGHISTORY"); Id (x=>x.Id).Column("ID"); References(x => x.Trust, "ACCOUNTNUMBER").PropertyRef("ACCTNBR").Fetch.Join(); Map(x => x.PostingDate).Column("POSTINGDATE"); } }