[英]How do I map a property with no setter and no backing property fluently with NHibernate?
[英]How can I ignore map property in NHibernate with setter
我需要使用NHibernate中的setter来忽略map属性,因为实体之间的关系是必需的。 这是我的简单模型
public class Person
{
public virtual Guid PersonId { get; set; }
public virtual string FirstName { get; set; }
public virtual string SecondName { get; set; }
//this is the property that do not want to map
public Credential Credential { get; set; }
}
public class Credential
{
public string CodeAccess { get; set; }
public bool EsPremium { get; set; }
}
public sealed class PersonMap : ClassMapping<Person>
{
public PersonMap()
{
Table("Person");
Cache(x => x.Usage(CacheUsage.ReadWrite));
Id(x => x.Id, m =>
{
m.Generator(Generators.GuidComb);
m.Column("PersonId");
});
Property(x => x.FirstName, map =>
{
map.NotNullable(true);
map.Length(255);
});
Property(x => x.SecondName, map =>
{
map.NotNullable(true);
map.Length(255);
});
}
}
我知道,如果我离开属性Credential {get;},我将不会使用NHibernate的地图,但是我需要在业务逻辑中设置该值。
提前致谢。
我不确定,但是您可以尝试以下方法:
Property(x => x.Credential, map => map.Access(Accessor.None));
使其成为只读属性
Property(x => x.Credential, map => map.Access(Accessor.ReadOnly));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.