[英]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.