如何使用setter忽略NHibernate中的映射属性
我需要忽略NHibernate中setter的map属性,因为需要实体之间的关系。这是我的简单模型如何使用setter忽略NHibernate中的映射属性,nhibernate,properties,fluent-nhibernate-mapping,Nhibernate,Properties,Fluent Nhibernate Mapping,我需要忽略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
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);
});
}
}
公共类人物
{
公共虚拟Guid PersonId{get;set;}
公共虚拟字符串FirstName{get;set;}
公共虚拟字符串SecondName{get;set;}
//这是不希望映射的属性
公共凭据凭据{get;set;}
}
公共类凭证
{
公共字符串代码访问{get;set;}
公共bool EsPremium{get;set;}
}
公共密封类PersonMap:ClassMapping
{
公众人物地图()
{
表(“人”);
缓存(x=>x.Usage(CacheUsage.ReadWrite));
Id(x=>x.Id,m=>
{
m、 生成器(Generators.GuidComb);
m、 栏目(“人名”);
});
属性(x=>x.FirstName,map=>
{
map.NotNullable(true);
地图长度(255);
});
属性(x=>x.SecondName,map=>
{
map.NotNullable(true);
地图长度(255);
});
}
}
我知道,如果我离开属性凭证{get;},我不会获取NHibernate的映射,但我需要在我的业务逻辑中设置值
提前谢谢。对此我不确定,但您可以试试:
Property(x => x.Credential, map => map.Access(Accessor.None));
只需将其设置为只读属性即可
Property(x => x.Credential, map => map.Access(Accessor.ReadOnly));
谢谢,但现在它抛出以下错误无法确定列的类型:MyApp.Credential,MyApp,Version=1.0.0,Culture=neutral,PublicKeyToken=null:NHibernate.Mapping.Column(Credential)谢谢,但现在它抛出以下错误无法确定列的类型:MyApp.Credential,MyApp,Version=1.0.0,Culture=neutral,PublicKeyToken=null,用于列:NHibernate.Mapping.Column(凭证)