Active Record学习笔记(四):处理Many-To-Many映射2012-01-04 博客园 jailu本文主要描述了如何使用Castle.ActiveRecord处理Many-To-Many映射。本文主要涉及了两个类:Student(学生)、Subject(学科),这两个类的关系是多对多的,因为一个学生学习多个学科,一个学科可以被多个学生学,下面是类图:

主要内容:1.编写数据库脚本2.HasAndBelongsToMany属性说明3.编写实体类4.编写调用代码一、编写数据库脚本由于Student与Subject是多对多关系,这里加入一个关联表Student_Subject来保存这些关系
Create Table [Student]( ID int identity(1,1) primary key, StudentName Varchar(50) not null) Create Table [Subject]( ID int identity(1,1) primary key, SubjectName Varchar(50) not null) Create Table [Student_Subject]( StudentID int not null, SubjectID int not null,)