NHibernate学习(7)—对于实现机理的猜测

这两天看了老赵的三篇关于NHibernate的文章,很受启发。
首先,对于如下代码的思考,对于一个Model类的代理做到不覆盖父类属性的处理方法的方式
Code
其次,对于NHibernate对于集合属性管理方面,确实做只读和只写两套属性集合在提高代码效率上确实很有必要,文中提到的Linq to SQL的处理方式给出了很巧妙的解决方式,即利用EntitySet<T>(Action 添加集合属性处理方法,Action 移除集合属性处理方法)来做到关系的维护。代码如下:
public partial class Question
{
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

private int _QuestionID;

private string _Name;

private EntitySet<Answer> _Answers;

public
Question()
{
this._Answers = new EntitySet<Answer>(
new Action<Answer>(this.attach_Answers),
new Action<Answer>(this.detach_Answers));
}

public int QuestionID { ... }

public string Name { ... }

public EntitySet<Answer> Answers
{
get
{
return this._Answers;
}
set
{
this._Answers.Assign(value);
}
}

private void attach_Answers(Answer entity)
{
entity.Question = this;
}

private void detach_Answers(Answer entity)
{
entity.Question = null;
}
}


本文参考自:我对NHibernate的感受(3):有些尴尬的集合支持
原文地址:https://www.cnblogs.com/haokaibo/p/1579940.html