枚举解析似乎与Fluent NHibernate无关 [英] Enum parsing doesn't seem to work with Fluent NHibernate

查看:148
本文介绍了枚举解析似乎与Fluent NHibernate无关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为称呼的枚举数据访问类:

I have a data access class with an Enum called Salutation:

 public enum Salutation
  {
    Unknown = 0,
    Dame = 1,
    etc
    Mr = 5,
    etc
  }

我正在使用NHibernate的类,直到今天早上我使用.hbm.xml文件进行映射。但是,现在我已经切换到使用Fluent NHibernate,但加载类的实例会失败(例如):

I am peristing the class with NHibernate, and up until this morning I was using .hbm.xml files for mapping. However, I've now switched to using Fluent NHibernate, but loading instances of the class fails with (for example):

[HibernateException:不能解析5作为称呼]

[HibernateException: Can't Parse 5 as Salutation]

正如你所看到的,5应该是可解析的,因为一个称呼(假设5是一个int,不可能从错误消息中得知)。

As you can see, 5 should be parseable as a Salutation (assuming 5 is an int, it's not possible to tell from the error message).

任何人都知道这里发生了什么?

Anyone know what's going on here?

谢谢

David

推荐答案

这比我想象的容易得多。

This is much easier than I thought.

Map(x => x.WhateverThePropertyNameIs).CustomType(typeof(MyEnumeration));

这篇关于枚举解析似乎与Fluent NHibernate无关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆