使用 Fluent Nhibernate 映射自定义枚举类
阅读一些来自吉米·博格德的帖子并想知道 - 究竟如何才能用流畅的冬眠来绘制这些野兽的地图?
对于这个来说,映射会是什么样子?
public class EmployeeType : Enumeration{
public static readonly EmployeeType
Manager = new EmployeeType(0, "Manager"),
Servant = new EmployeeType(1, "Servant"),
AssistantToTheRegionalManager = new EmployeeType
(2, "Assistant to the Regional Manager");
private EmployeeType() { }
private EmployeeType(int value, string displayName) :
base(value, displayName) { }
}
Reading some posts from Jimmy Boggard and wondering - how exactly is it possible to map those beasts with fluent nhibernate?
How mapping would look like for this?
public class EmployeeType : Enumeration{
public static readonly EmployeeType
Manager = new EmployeeType(0, "Manager"),
Servant = new EmployeeType(1, "Servant"),
AssistantToTheRegionalManager = new EmployeeType
(2, "Assistant to the Regional Manager");
private EmployeeType() { }
private EmployeeType(int value, string displayName) :
base(value, displayName) { }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
啊……这很容易。在 CodeCampServer 中 - 有一个通用的 EnumerationType 类。想法很简单 - 我们只需要使用 EnumerationType 包装域模型枚举值对象,以便将其映射为整数(或其他任何必要的值)。
Ah... it was easy. In CodeCampServer - there's a generic EnumerationType class. Idea is simple - we just need to wrap our domain model enumeration value object with EnumerationType in order to map it as integer (or anything else if necessary).
您还可以从 IUserType 创建派生并指定如何存储和检索数据库上特定列的信息、序列化和反序列化枚举。
查看这篇文章,了解 IUserType 基础知识的简单说明。
You can also create derive from IUserType and specify how to store an retrieve the information from a specific column on the database, serializing and deserializing the enumeration.
Check this article for a simple explanation of the basics of IUserType.