我有一个类似于以下内容的类(注意!名称已更改以保护无辜者):
public class Person
{
public virtual int Id { get; private set; }
public virtual string Name { get; set; }
public virtual DateTime Birthday { get; set; }
public virtual TimeSpan Age { get { return DateTime.Now - this.Birthday; } }
}
我使用 Fluent NHibernate 来配置我的映射:
public class PersonMap : ClassMap<Person>
{
public PersonMap()
{
Id(x => x.Id);
Map(x => x.Name);
Map(x => x.Birthday);
}
}
问题是这会引发异常:
找不到财产设置者
“人”类中的“年龄”
如果年龄未标记为虚拟,我会得到:
以下类型不得用作
代理:人:方法 get_Age 应该
是“公共/受保护的虚拟”或
“受保护的内部虚拟”
当然它找不到二传手,也不应该!我怎样才能使这个映射工作?
对我来说真正的问题是为什么流畅的 NHibernate 会尝试映射 Age 属性?它甚至不在你的映射中。在整个自动映射功能之前,我只使用过早期版本的 Fluent NHibernate,并且从未遇到过这个问题。
我怀疑您的约定导致它尝试映射年龄,或者您以某种方式启用了自动映射,这与您的手动映射相冲突。
另请注意,Fluent NHibernate 最近在某种程度上更改了约定。所以我会看一下以下文档:
http://wiki. Fluentnhibernate.org/show/Conventions http://wiki.fluentnhibernate.org/show/AutoMapping
http://wiki. Fluentnhibernate.org/show/ConvertingToNewStyleConventions http://wiki.fluentnhibernate.org/show/ConvertingToNewStyleConventions
http://wiki. Fluentnhibernate.org/show/AutoMapping http://wiki.fluentnhibernate.org/show/AutoMapping
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)