【IT168技术文档】
摘要:本文详细介绍了ActiveRecord中的基本映射,对于关联映射会在后续文章中通过一些具体的实例来说明。
主要内容
简单映射
1.ActiveRecordAttribute
2. PrimaryKeyAttribute
3.CompositeKeyAttribute
4.PropertyAttribute
5.FieldAttribute
一.ActiveRecordAttribute
每一个实体类都必须继承于基类ActiveRecordBase,并在实体类上设置特性ActiveRecordAttribute,示例代码
ActiveRecordAttribute说明//指定数据库表名 [ActiveRecord("Blogs")] public class Blog : ActiveRecordBase { // } //不指定数据库表名 [ActiveRecord] public class Blog : ActiveRecordBase { // }

二.PrimaryKeyAttribute
在实体类中,通过PrimaryKeyAttribute来指定表的主键,示例代码
//指定主键字段名 [ActiveRecord()] public class Blog : ActiveRecordBase { private int id; [PrimaryKey("blog_id")] public int Id { get { return id; } set { id = value; } } } //不指定主键字段名 [ActiveRecord()] public class Blog : ActiveRecordBase { private int id; [PrimaryKey] public int Id { get { return id; } set { id = value; } } }