我需要在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的地图,但我需要在我的业务逻辑中设置值。
提前致谢。
答案 0 :(得分:0)
我不确定这一点,但你可以尝试一下:
Property(x => x.Credential, map => map.Access(Accessor.None));
答案 1 :(得分:0)
只需将其设为只读属性
即可Property(x => x.Credential, map => map.Access(Accessor.ReadOnly));