Is it OK to call virtual properties from the constructor of a NHibernate entity?

前端 未结 6 602
有刺的猬
有刺的猬 2020-12-11 01:02

take a look at this example code:

public class Comment
{
    private Comment()
    { }

    public Comment(string text, DateTime creationDate, string authorE         


        
6条回答
  •  情歌与酒
    2020-12-11 01:08

    I know that FxCop complains if you call a virtual method in your constructor, but I don't know what FxCop says whether you're calling a virtual property in your constructor ...
    I would think that FxCop will complain as well since a property is translated to a method in IL.

    You can also create your properties as 'non-virtual', and just specify 'lazy=false' on your 'class mapping' in NHIbernate. This won't affect the lazy-load behavior of collections.

    (I do it all the time, since I do not like that my infrastructure (NHibernate) requires me to have the properties virtual.
    I also don't know whether the performance benefit of having dynamic proxies in NHibernate is significant).

提交回复
热议问题