我有一个名为 IEntity 的接口(interface),到目前为止它有一个名为 Entity 的具体类,这个接口(interface)有一个只读属性。我宁愿映射接口(interface),但是因为接口(interface)不能有私有(private)字段,我不能使用带前缀选项的选项驼峰字段来映射它,所以我该怎么办?
public interface IEntity
{public readonly string Name{get;} }
public class Entity:IEntity
{public readonly string Name{get;}}
public class EntityMap:ClassMap<IEntityMap>
{
//how to map the readonly property
}
最佳答案
尝试:
<property name="Name" type="string" access="readonly"/>
NHibernate Read Only Property Mapping
如果你使用 Fluent:
Mapping a read-only property with no setter using Fluent NHibernate
我认为这也很有用:
How to map an interface in nhibernate?
已更新
我认为第一步是更正您的代码。然后尝试发布您的映射文件或流畅的配置。如果不清楚您要实现的目标,我们无法为您提供帮助。
关于c# - 使用 nhibernate 有什么方法可以在接口(interface)中映射只读属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6323025/