Fluent NHibernate NaturalId missing?
本文关键字:missing NaturalId NHibernate Fluent | 更新日期: 2023-09-27 18:37:17
我有一个非常简单的映射,我正在尝试做。我正在遵循NHibernate 3.0食谱,我遇到了FluentNHibernate.dll中缺少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
找到了答案。不知道为什么,但你必须在 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();
}
}
}