2013-01-10 35 views
3

我有一個功能NHibernate項目我的工作,並做一些測試我遇到了一個很奇怪的錯誤:奇誤差建築FluentNH配置

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

報告的相關實體是:

{Name = "<>c__DisplayClass3" FullName = "TPLLCPortal.Domain.Account+<>c__DisplayClass3"}

我沒有叫任何DisplayClass類,但我有一個Account實體。我使用的是這樣的一個主鍵約定:

public class PrimaryKeyConvention : IIdConvention 
{ 
    public void Apply(IIdentityInstance instance) 
    { 
     instance.GeneratedBy.GuidComb(); 
    } 
} 

Account類從EntityBase類聲明的ID爲繼承:

/// <summary> 
/// Gets or sets the id. 
/// </summary> 
/// <value>The id.</value> 
public virtual Guid Id { get; protected internal set; } 

我相信,我設置正確配置配置以及約定正在被拾取,但以防萬一我添加了覆蓋並專門映射Account類的ID。沒有骰子。

任何想法是怎麼回事?

我在NHibernate 3.3.1.4000上使用FNH 1.3.0.733(都裝載了NuGet)。

回答

4

看起來像我想出來的。 This SO answer有關鍵。由於類中的某些方法使用lambda表達式,因此編譯器會創建可通過指定!type.IsDefined(typeof(CompilerGeneratedAttribute), false)作爲ShouldMap覆蓋的一部分在DefaultAutomappingConfiguration中排除的類。