NHibernate helper properties in an object

I have an NHibernate object that looks like this:

public class Offender
{
    public virtual string FName { get; set; }
    public virtual string MName { get; set; }
    public virtual string LName { get; set; }

    public string FullName
    {
        get
        {
            return FName + " " + MName + " " + LName;
        }
    }
}

The full name is a convenience property and is not in the database. But NHibernate does not like the property to be there and throw this exception:

The following types may not be used as proxies:
mPSOR.Data.Entities.SORPerson: method get_FullName should be 'public/protected virtual' or 'protected internal virtual'

Is there a way to enable an auxiliary property? Or do I need to calculate the calculations like this when compiling the DTO, or in my opinion?

+3
source share
3 answers

NHibernate needs all properties to be virtual ... even fake properties such as Full Name.

Just make it virtual and it will work:

public virtual string FullName
{
}
+5
source

. NHibernate , -, . - , , , .

+3

You can also use the formula in your smooth comparisons:

Map(x => x.LName).Formula("FName + ' ' + MName + ' ' + LName");

+1
source

Source: https://habr.com/ru/post/1791317/


All Articles