摘要:
Castle ActiveRecord 通过特性处理数据表关联关系。Many-to-one: BelongsToAttributeOne-to-many: HasManyAttributeMany-to-many: HasAndBelongsToManyAttribute1. One-to-Many / Many-to-One多数时候,Many-to-One 和 One-To-Many 总算相伴而生的。在下面的例子中,每个组可以有多个用户加入。我们通过在 User 类型里面使用 BelongsTo 添加一个名为 "GroupId" 的字段来处理 Many-to-One 的关 阅读全文
摘要:
ActiveRecord 的 CRUD 操作基本上都是由 ActiveRecordBase 的静态方法完成。其实例(含子类型)方法,以及 ActiveRecordMediator 只是对这些静态方法的包装调用而已。当然,ActiveRecordBase 方法又是对 NHibernate Session 方法的包装。我们用下面这个实体来简单演示一下常用方法的使用。[ActiveRecord("Users")]public class User : ActiveRecordBase{private int id;[PrimaryKey(PrimaryKeyType.Identi 阅读全文
摘要:
ActiveRecord 的多数据库配置基本沿袭了 NHibernate 的思想,只不过在配置文件结构上作了些调整。1. 采用继承方式,归纳使用同一数据库的类型。比如 A、B、C、D、E 中 A、B连接到数据库Test1,C、D连接到Test2,而E连接到缺省的Test,那么具体的代码就会是下面这种方式。public abstract class Test1Base : ActiveRecordBase{}public abstract class Test2Base : ActiveRecordBase{}[ActiveRecord("A")]public class A 阅读全文
摘要:
http://www.rainsts.net/article.asp?id=243有意无意的,很多文章都没有提及 ActiveRecordMediator 。ActiveRecordMediator最大的用途是:即便你的实体类不是继承自 ActiveRecordBase (不推荐这么做),它也可以进行同等的创建、查找等操作;另外这个类实现了很多常用的方法,我们直接使用它就没必要为每个实体类写一堆相同的操作方法了(ActiveRecordBase的静态方法干吗声明为 protected internal?)。[ActiveRecord]public class User{private int 阅读全文
摘要:
http://www.rainsts.net/article.asp?id=242在ActiveRecord中级联操作为我们带来很多方便,但是一些细节地方需要注意。[ActiveRecord("Users")]public class User : ActiveRecordBase{public User(){}public User(string name) : this(){this.name = name;}private int id;[PrimaryKey(PrimaryKeyType.Identity)]public int Id{get { return id 阅读全文