两张表的FluentNhibernate映射,使用映射中的主键的唯一主键

时间:2018-08-16 08:02:00

标签: c# nhibernate fluent-nhibernate nhibernate-mapping

我正在用C#编写桌面项目。我正在使用Nhibernate与数据库进行通信。此外,我将FluentNhibernate用于模型的映射,但是我陷入了映射的某些部分。这是我在ProductMap中的映射类

地图丢失

   public LosingMap()
        {
            Id(x => x.id);
            Map(x => x.reason);
            Map(x => x.quantity);
            Map(x => x.lose_sum);
            Map(x => x.rate);
            Map(x => x.deleted);
            Map(x => x.create_date);
            Map(x => x.update_date);
            References(x => x.currency).Column("CurrencyCode");
            Table("Loosing");


        }
    }

这是CurrencyMap

CurrencyMap

public CurrencyMap()
    {

        Id(x => x.id);
        Map(x => x.code).UniqueKey("currency_code");


        Map(x => x.name);
        Map(x => x.shname);
        Map(x => x.symbol);
        Map(x => x.deleted);
        HasMany(x => x.Losings).Cascade.All();
        Table("currency");
    }
}

我在货币表中有一个主键和一个唯一键,如何在我的LoosingMap类中引用我的唯一键而不是主键?

1 个答案:

答案 0 :(得分:4)

使用java.lang.AssertionError: 1 expectation failed. Response body doesn't match expectation. Expected: The content to match the given JSON schema. warning: the following keywords are unknown and will be ignored: [$id] level: "warning" schema: {"loadingURI":"file:/D:/workspace/restAssuredFramework/target/test-classes/get.json#","pointer":""} domain: "syntax" ignored: ["$id"] warning: the following keywords are unknown and will be ignored: [$id] level: "warning" schema: {"loadingURI":"file:/D:/workspace/restAssuredFramework/target/test-classes/get.json#","pointer":"/properties/IntegrationEntities"} domain: "syntax" ignored: ["$id"] warning: the following keywords are unknown and will be ignored: [$id] level: "warning" 上的KeyColumn

CurrencyMap

根据FluentNHibernate "HasMany / one-to-many" documentation,“与引用一样,外键默认为Author_id,您可以使用KeyColumn方法覆盖它,或使用Conventions更改默认行为。”,因此您也可以使用:

public CurrencyMap()
    {

        Map(x => x.id); // Optional
        KeyColumn(x => x.code)


        Map(x => x.name);
        Map(x => x.shname);
        Map(x => x.symbol);
        Map(x => x.deleted);
        HasMany(x => x.Losings).Cascade.All();
        Table("currency");
    }
}