zoukankan      html  css  js  c++  java
  • 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):有些尴尬的集合支持
  • 相关阅读:
    Eclipse IDE中Android项目打红叉的解决方法
    控件:PopupWindow 弹出窗口(基本操作)
    控件:AnalogClock与DigitalClock 时钟组件
    四大组件之一 BroadcastReceiver (拦截短信并屏蔽系统的Notification .)
    四大组件之一 文件存储_文本文件
    控件:Chronometer 计时器(定时震动)
    计算页面执行时间的两种方法
    URL解析的几种模式以及拟静态重定向问题
    SSH 文件上传错误:encountered 1 errors during the transfer终极解决方法:
    php过滤提交信息防注入
  • 原文地址:https://www.cnblogs.com/haokaibo/p/1579940.html
Copyright © 2011-2022 走看看