2012-06-13 41 views
0

我有一個非常簡單的映射,我試圖做。我遵循NHibernate 3.0 Cookbook,並且遇到了FluentNHibernate.dll中缺少的NaturalId()方法問題。這本書讓我建立這個:流利NHibernate的NaturalId失蹤?

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using FluentNHibernate.Mapping; 
using Eg.Core; 

namespace Eg.FluentMappings.Mappings 
{ 
    public class ProductMapping : ClassMap<Product> 
    { 
     public ProductMapping() 
     { 
      Id(p => p.Id) 
       .GeneratedBy.GuidComb(); 
      DiscriminateSubClassesOnColumn("ProductType"); 
      Version(p => p.Version); 
      NaturalId() 
       .Not.ReadOnly() 
       .Property(parentIsRequired => parentIsRequired.Name); 
      Map(p => p.Description); 
      Map(p => p.UnitPrice) 
       .Not.Nullable(); 
     } 
    } 
} 

當我嘗試編譯它,我得到一個錯誤:「NaturalId」這個名字不會在當前上下文中。我錯過了另一個DLL或其他東西?

我環顧四周,發現很多。這是一個似乎可以回答的問題,但我無法使用map.NaturalId()Map.NaturalId()來使用它。 SharpArchitecture/Fluent NHibernate

回答

1

找到了答案。不知道爲什麼,但你必須在NaturalId()上使用base關鍵字。以下是我修改的課程:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using FluentNHibernate.Mapping; 
using Eg.Core; 

namespace Eg.FluentMappings.Mappings 
{ 
    public class ProductMapping : ClassMap<Product> 
    { 
     public ProductMapping() 
     { 
      Id(p => p.Id) 
       .GeneratedBy.GuidComb(); 
      DiscriminateSubClassesOnColumn("ProductType"); 
      Version(p => p.Version); 
      base.NaturalId() 
       .Not.ReadOnly() 
       .Property(parentIsRequired => parentIsRequired.Name); 
      Map(p => p.Description); 
      Map(p => p.UnitPrice) 
       .Not.Nullable(); 
     } 
    } 
}