简体   繁体   中英

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. 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.

Thanks in advance.

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

Property(x => x.Credential, map => map.Access(Accessor.None));

使其成为只读属性

Property(x => x.Credential, map => map.Access(Accessor.ReadOnly));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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