简体   繁体   English

如何使用setter忽略NHibernate中的map属性

[英]How can I ignore map property in NHibernate with setter

I need to ignore map property with setter in NHibernate, because the relationship between entities is required. 我需要使用NHibernate中的setter来忽略map属性,因为实体之间的关系是必需的。 This is my simple model 这是我的简单模型

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);
        });


    }

}

I know that if I leave the property Credential {get;} I was not going to take the map of NHibernate, but I need to set the value in my bussiness logic. 我知道,如果我离开属性Credential {get;},我将不会使用NHibernate的地图,但是我需要在业务逻辑中设置该值。

Thanks in advance. 提前致谢。

我不确定,但是您可以尝试以下方法:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM