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):有些尴尬的集合支持
  • 相关阅读:
    有没有开源软件可以批量安装操作系统
    MarkMan – 马克鳗,让设计更有爱!
    Tomboy : Simple note taking
    wikipad这个软件可以深入研究是基于pywebkit linux uubntu 下有分发包
    guard/guardlivereload
    Frequently Asked Questions — Scrapy 0.15.1 documentation
    Tornado Web服务器
    稀疏矩阵的存储格式 之 CSR/CSC
    Zen Coding — a new way of writing HTML and CSS code
    felinx / labs / source — Bitbucket
  • 原文地址:https://www.cnblogs.com/haokaibo/p/1579940.html
Copyright © 2011-2022 走看看