【发布时间】:2010-12-01 18:25:32
【问题描述】:
我正在按照http://wiki.fluentnhibernate.org/Getting_started 教程使用 Fluent NHibernate 创建我的第一个 NHibernate 项目
我有两张桌子
1) 带有字段的帐户
Id
AccountHolderName
AccountTypeId
2) 带字段的 AccountType
Id
AccountTypeName
目前账户类型可以是储蓄或活期 所以表 AccountTypes 存储 2 行 1 - 储蓄 2 - 当前
对于AccoutType 表我已经定义了枚举
public enum AccountType {
Savings=1,
Current=2
}
对于 Account 表,我定义了实体类
public class Account {
public virtual int Id {get; private set;}
public virtual string AccountHolderName {get; set;}
public virtual string AccountType {get; set;}
}
流畅的nhibernate映射是:
public AgencyMap() {
Id(o => o.Id);
Map(o => o.AccountHolderName);
Map(o => o.AccountType);
}
当我尝试运行解决方案时,它给出了一个异常 - InnerException = {"(XmlDocument)(2,4): XML validation error: The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has内容不完整。预期的可能元素列表:命名空间“ur...”中的“元、子选择、缓存、同步、注释、元组、id、复合 ID”。
我猜这是因为我没有为 AccountType 指定任何映射。
问题是:
- 如何使用 AccountType 枚举 而不是 AccountType 类?
- 也许我走错了路。有没有更好的方法来做到这一点?
谢谢!
【问题讨论】:
标签: .net enums fluent-nhibernate