小编S.S*_*ani的帖子

在 Fluent NHibernate 中共享字段作为复合键和外键

请考虑以下映射代码:

public sealed class BankMapping : ClassMap<Bank>
{
    public BankMapping()
    {
        CompositeId()
            .KeyProperty(x => x.SerialNumber, "SerialBankRef")
            .KeyProperty(x => x.FinancialPeriodId, "FinancialPeriodRef");
        Map(x => x.Code);
        Map(x => x.Title);
        Map(x => x.Comment);
        Map(x => x.IsActive);            
        HasMany(x => x.BankBranchs).KeyColumns.Add(new[] { "SerialBankRef", "FinancialPeriodRef" });

    }
}
Run Code Online (Sandbox Code Playgroud)

BankBranch映射代码为:

public sealed class BankBranchMapping : ClassMap<BankBranch>
{
    public BankBranchMapping()
    {
       CompositeId()
            .KeyProperty(x => x.FinancialPeriodId, "FinancialPeriodRef")
            .KeyProperty(x => x.SerialNumber, "SerialNumber");
        Map(x => x.Code);
        Map(x => x.Title);
        Map(x => x.Comment);
        Map(x => x.IsActive);
        Map(x => x.Address);
        Map(x => …
Run Code Online (Sandbox Code Playgroud)

nhibernate fluent-nhibernate-mapping

3
推荐指数
1
解决办法
2921
查看次数