如何使用 DefaultAutomappingConfiguration 在 FluentNHibernate 中映射私有字段
此处给出的指导 http:// Fluentnhibernate.org/blog/2010 /05/23/feature-focus-fields.html 建议从 V1.1 开始,Fluent NHibernate 的自动映射功能支持映射到私有字段。
因此,给出以下代码,NHiberate 应该能够映射到 myValue
字段。
public class SomeEntity
{
private string myValue;
public virtual int Id { get; set; }
}
public class DomainAutomappingConfiguration : DefaultAutomappingConfiguration
{
public override bool ShouldMap(FluentNHibernate.Member member)
{
return (member.IsProperty && member.IsPublic && member.CanWrite) ||
(member.IsField && member.IsPrivate);
}
}
但是,当我运行此代码并尝试映射时,出现以下异常:
NHibernate.PropertyNotFoundException:无法找到属性“myValue”的 getter 类......
我正在使用 FluentNHibernate 1.1 和 NHibernate 3.0.0.2001
我做错了什么?
The guidance given here http://fluentnhibernate.org/blog/2010/05/23/feature-focus-fields.html suggests that from V1.1 the automapping feature of Fluent NHibernate supports mapping to private fields.
So given the following code, NHiberate should be able to map to the myValue
field.
public class SomeEntity
{
private string myValue;
public virtual int Id { get; set; }
}
public class DomainAutomappingConfiguration : DefaultAutomappingConfiguration
{
public override bool ShouldMap(FluentNHibernate.Member member)
{
return (member.IsProperty && member.IsPublic && member.CanWrite) ||
(member.IsField && member.IsPrivate);
}
}
However when I run this code and try to map, I get the following exception:
NHibernate.PropertyNotFoundException : Could not find a getter for property 'myValue' in
class.....
I am using FluentNHibernate 1.1 and NHibernate 3.0.0.2001
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改:
至:
我不确定这是否适合您,但您收到的错误是指定私有字段时缺少 {get;} 。希望这会让您走上正轨。我没有尝试过映射私有字段。
祝你好运。
Change:
To:
I am not sure if this will do it for you, but the error you are receiving is the lack of the {get;} when designating the private field. Hopefully this will put you on the right track. I have not tried mapping private fields.
Good luck.