如何使用 Fluent Nhibernate 的 AutoPersistenceModel 忽略组件的属性?
我正在使用 Fluent NHibernate AutoMappings 来映射我的实体,包括一些组件对象。 其中一个组件对象包含如下属性:
public string Value
{
set _value = value;
}
这会导致 NHibernate.PropertyNotFoundException:“无法找到属性‘Value’的 getter...”
我想忽略此属性。
我尝试为组件类创建 IAutoMappingOverride,但出于同样的原因,我无法使用 AutoMapping<>.IgnoreProperty(x => x.Value) 。 “属性或索引器‘MyComponent.Value’不能在这种情况下使用,因为它缺少 get 访问器”
我还查看了 IComponentConvention,但看不到如何使用此约定更改映射。
任何帮助将不胜感激...
谢谢
I am using Fluent NHibernate AutoMappings to map my entities, including a few component objects.
One of the component objects includes a property like the following:
public string Value
{
set _value = value;
}
This causes an NHibernate.PropertyNotFoundException: "Could not find a getter for property 'Value'..."
I want to ignore this property.
I tried creating an IAutoMappingOverride for the component class but I couldn't use AutoMapping<>.IgnoreProperty(x => x.Value) for the same reason.
"The property or indexer 'MyComponent.Value' cannot be used in this context because it lacks the get accessor"
I've also looked at IComponentConvention but can't see anyway of altering the mappings with this convention.
Any help would be appreciated...
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用:
例如
Reveal.Member 可以在 Fluent NHibernate 需要表达式的任何地方使用。这可用于公开私有/受保护的属性和字段。
You can use:
Eg
Reveal.Member can be used anywhere Fluent NHibernate expects an expression. This can be used to expose private/protected properties and fields.
您可以在映射文件中使用 OverrideAll()。如果您不知道它将成为其成员的类型,那么您需要使用此版本将成员指定为字符串。以下是 Fluent Nhibernate Wiki 中的示例。
You can use OverrideAll() in your mapping file. If you don't know the type that it will be a member of, then you need to use this version specify the member as a string. Here's the example from the Fluent Nhibernate Wiki.
如果您向属性添加私有 Get 方法,您也许能够使覆盖起作用。
You might be able to get the override to work if you add a private Get method to your property.
我已经尝试过私有和受保护的 get 访问器,但除非访问器是公共的,否则覆盖不会编译。
“属性或索引器不能在此上下文中使用,因为它缺少 get 访问器”
I've tried both a private and protected get accessor but the override won't compile unless the accessor is public.
"The property or indexer cannot be used in this context because it lacks the get accessor"
您可以添加公共 getter 抛出
NotSupportedException
以使编译器满意:You can add public getter throwing
NotSupportedException
to make compiler happy: