簡體   English   中英

流暢的 nhibernate:相同類型的 compositeid(),獲取未映射 ID 的消息

[英]fluent nhibernate: compositeid() of same types, getting message no id mapped

我已經搜索過 Google 和 SO,但沒有遇到遇到同樣問題的人。 這是我的模型:

public class Hierarchy
{
    public virtual Event Prerequisite { get; set; }
    public virtual Event Dependent { get; set; }

    public override bool Equals(object obj) 
    {
        var other = obj as Hierarchy; 
        if (other == null) 
        { 
            return false; 
        } 
        else 
        { 
            return this.Prerequisite == other.Prerequisite && this.Dependent == other.Dependent; 
        } 
    }

    public override int GetHashCode()
    {
        return (Prerequisite.Id.ToString() + "|" + Dependent.Id.ToString()).GetHashCode();
    }
}

這是我的映射:

public class HierarchyMap : ClassMap<Hierarchy>
{
    public HierarchyMap()
    {
        CompositeId()
            .KeyReference(h => h.Prerequisite, "PrerequisiteId")
            .KeyReference(h => h.Dependent, "DependentId");
    }
}

這是永遠存在的結果:

{"The entity 'Hierarchy' doesn't have an Id mapped. Use the Id method to map your identity property. For example: Id(x => x.Id)."}

是否需要進行一些特殊配置才能啟用復合 ID? 我有最新的 FNh(截至 2012 年 6 月 29 日)。

編輯

我認為這個問題是開放的,即使我決定映射一個 Id 並引用 2 個事件而不是使用 CompositeId。 隨意提出一個答案。

我發現這是由於自動映射試圖自動映射 ID 即使我有我班級的實際地圖 - 它仍然嘗試自動映射 ID。 一旦我從自動映射中排除了該類,它就可以正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM