【问题标题】:Fluent Nhibernate Mapping流畅的休眠映射
【发布时间】:2011-11-15 08:00:29
【问题描述】:

我有 2 个类,MasterItem 和 ItemUOM。 ItemUOM 是我已映射的视图,而 MasterItem 是一个直截了当的表。 是否可以在 ItemUOM 中引用 MasterItem。

ItemUOM 类:

 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 映射

    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);
    }

如何引用“MasterItem”类。

谢谢弗朗索瓦

【问题讨论】:

    标签: .net nhibernate mapping fluent


    【解决方案1】:

    您需要移除 MasterItemID 并使用References(x =&gt; x.MasterItem) 等。

    【讨论】:

    • 我没有对密钥的引用,请记住这是一个 SQL 视图。
    • 我需要告诉映射 MasterItemID 映射回表 MasterItem。
    【解决方案2】:

    看来你需要一个普通的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");
    }
    

    并且 MasterItem 应该有自己的映射,您可以在其中指定其所有属性。

    【讨论】:

    • 我得到一个无效的列名“MasterItemID”。如果我使用 sql 查询并在 SQL 中执行它,它就可以工作。
    猜你喜欢
    • 2011-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-23
    • 2012-07-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多