这两天看了老赵的三篇关于NHibernate的文章,很受启发。
首先,对于如下代码的思考,对于一个Model类的代理做到不覆盖父类属性的处理方法的方式
Code
public class ArticleLazyProxy : Article{ public override string TagNames { get { var tagNames = // 加载数据 base.TagNames = tagNames; return base.TagNames; } set { base.TagNames = value; } }}
其次,对于NHibernate对于集合属性管理方面,确实做只读和只写两套
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; } }属性集合在提高代码效率上确实很有必要,文中提到的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):有些尴尬的集合支持
赵劼 /
CC BY 2.5
转载于:https://www.cnblogs.com/haokaibo/archive/2009/10/09/1579940.html
相关资源:各显卡算力对照表!