简体   繁体   中英

Fluent Nhibernate Mapping

I have 2 classes, MasterItem and ItemUOM. ItemUOM is a view that i've mapped and MasterItem a straight forward table. Is it possible to reference MasterItem in ItemUOM.

ItemUOM class:

 public class ItemUOM : EntityBase<ItemUOM>
{
    public virtual string ItemAlias { get; set; }
    public virtual string Code { get; set; }
    public virtual string UOM { get; set; }
    public virtual decimal PackSize { get; set; }
    public virtual long MasterItemID { get; set; }
    **public virtual DomainEntities.MasterItem MasterItem { get; set; }**
}

ItemUOM mapping

    public ItemUOMMapping()
    {
        Table("View_ItemUOM");
        Id(x => x.ID);
        Map(x => x.Code);
        Map(x => x.ItemAlias);
        Map(x => x.UOM);
        Map(x => x.PackSize);
    }

How can I reference to class "MasterItem".

Thanks Francois

您需要删除 MasterItemID并使用References(x => x.MasterItem)等。

Looks you need a regular many-to-one :

public ItemUOMMapping()
{
    Table("View_ItemUOM");
    Id(x => x.ID);
    Map(x => x.Code);
    Map(x => x.ItemAlias);
    Map(x => x.UOM);
    Map(x => x.PackSize);
    References(x => x.MasterItem)
        .Column("MasterItemID");
}

And MasterItem should have its own mapping where you specify all its properties.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM