我用这个How do you map an enum as an int value with fluent NHibernate?映射在过去,但我最近升级到NHibernate 3,这似乎并没有工作了。我在EnumConvention类中放置了断点,但它们没有被击中。正在访问数据库的查询将枚举作为默认配置的字符串。使用流利NHibernate和NHibernate的地图枚举作为Int
这对NHibernate 3是如何工作的?
更新
这里是生成的映射文件的一部分:
<property name="ComponentType" type="FluentNHibernate.Mapping.GenericEnumMapper`1[[...ComponentType, ..., Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], FluentNHibernate, Version=1.1.0.0, Culture=neutral, PublicKeyToken=8aa435e3cb308880">
<column name="ComponentTypeId" />
</property>
似乎不正确的,当枚举指定了IUserTypeConvention
它会使用GenericEnumMapper
。
这里是我的约定:
public class EnumConvention : IUserTypeConvention
{
public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
{
criteria.Expect(e => e.Property.PropertyType.IsEnum);
}
public void Apply(IPropertyInstance instance)
{
instance.CustomType(instance.Property.PropertyType);
}
}
我真的看不到你从这个练习中获得什么,但是这可能因为某种原因被删除了,因为他们的力量发现需要保持它 – Baz1nga 2011-03-22 04:32:35
我没有看到它消失的任何地方,它只是似乎没有工作了。那么该怎么办呢?做'Map(...).CustomType()'不起作用。它会导致问题。我会尝试做一个自定义的IUserType,看看现在是否可行。 –
2011-03-22 14:31:05
林说,你有任何理由将其存储为一个int而不是枚举吗?随着mem nt一个概率我真的没看到一个原因..字符串枚举是代码安全.. – Baz1nga 2011-03-22 20:00:09