学习日记:业务模型类的建立

  业务模型的建立包含几个过程:CDM-->PDM-->DATABASE-->MODEL.
  先在根据需求分析,概要设计文档,用PowerDesigner设计概念模型CDM(E-R图),后用PowerDesigner 转换为物理模型PDM,再由PDM生成数据库脚本(或直接导成库),然后生成库.
  生成库后利用Castle的自动生成器生成业务模型类(Castle.ActiveRecord.Generator).

  举例:多对多关系业务模型类
  
 1.CDM:People; Company 
    学习日记:业务模型类的建立_第1张图片
 2.CDM -->PDM :PDM自动生成 People,Company的对照表,PeopleCompany
学习日记:业务模型类的建立_第2张图片
 3.PDM --> SqlServer: People,Company,PeopleCompany
 
 4.SqlServer --> Model: 由Castle.ActiveRecord.Generator生成的MODEL,也为三个
学习日记:业务模型类的建立_第3张图片

实际的MOEDL应为2个,如
[ActiveRecord("company")]
public class Company : ActiveRecordBase
{
    private int id;
    private String name;
    private IList _people;

    public Company()
    {
    }

    public Company(string name)
    {
        this.name = name;
    }

    [PrimaryKey]
    public int Id
    {
        get { return id; }
        set { id = value; }
    }

    [Property]
    public String Name
    {
        get { return name; }
        set { name = value; }
    }

    [HasAndBelongsToMany( typeof(Person),
      Table="people_companies",
      ColumnRef="person_id", ColumnKey="company_id" )]
    public IList People
    {
        get { return _people; }
        set { _people = value; }
    }
}

[ActiveRecord("people")]
public class Person : ActiveRecordBase
{
    private int _id;
    private String _name;
    private IList _companies;

    public Person()
    {
        _companies = new ArrayList();
    }

    [PrimaryKey]
    public int Id
    {
        get { return _id; }
        set { _id = value; }
    }

    [Property]
    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }

    [HasAndBelongsToMany( typeof(Company),
      Table="people_companies",
      ColumnRef="company_id", ColumnKey="person_id" )]
    public IList Companies
    {
        get { return _companies; }
        set { _companies = value; }
    }
}


转载于:https://www.cnblogs.com/tonyman/archive/2006/07/07/444819.html

你可能感兴趣的:(学习日记:业务模型类的建立)