可以从NHibernate实体的构造函数中调用虚拟属性吗?

Asa*_*vid 19 nhibernate

看看这个示例代码:

public class Comment
{
    private Comment()
    { }

    public Comment(string text, DateTime creationDate, string authorEmail)
    {
        Text = text;
        CreationDate = creationDate;
        AuthorEmail = authorEmail;
    }

    public virtual string Text { get; private set; }
    public virtual DateTime CreationDate { get; set; }
    public virtual string AuthorEmail { get; private set; }
}
Run Code Online (Sandbox Code Playgroud)

我知道从构造函数调用虚拟成员函数被认为是不好的做法,但是在NHibernate中我需要虚拟属性来支持延迟加载.在这种情况下它被认为是好的吗?

Mar*_*ers 5

我很确定这很好,但如果你担心你总是可以在参数较少的构造函数调用之后分配属性.