Welcome

首页 / 软件开发 / .NET编程技术 / Castle ActiveRecord学习实践(3) 映射基础

Castle ActiveRecord学习实践(3) 映射基础2011-02-03 cnblogs terrylee主要内容

简单映射

1.ActiveRecordAttribute

2. PrimaryKeyAttribute

3.CompositeKeyAttribute

4.PropertyAttribute

5.FieldAttribute

一.ActiveRecordAttribute

每一个实体类都必须继承于基类ActiveRecordBase,并在实体类上设置特性ActiveRecordAttribute,示例代码

//指定数据库表名
[ActiveRecord("Blogs")]
public class Blog : ActiveRecordBase
{
//
}
//不指定数据库表名
[ActiveRecord]
public class Blog : ActiveRecordBase
{
//
}

ActiveRecordAttribute说明

属性说明示例
Table指定持久化类所对应的数据库表名,如果表名与类名相同,可以省略[ActiveRecord("Blogs")] [ActiveRecord(Table="Blogs")]
Schema指定Schema的名字Schema="ARDemo"
Proxy指定一个接口,在延迟装载时作为代理使用 
DiscriminatorColumn识别器的字段名DiscriminatorColumn="Blog"
DiscriminatorType识别器的字段类型DiscriminatorType="String"
DiscriminatorValue识别器字段的值 
Where指定一个附加SQL的Where子句Where="IsPost = 0"
Lazy指定是否延迟加载Lazy=true|false