自己动手写ORM框架(三):关系映射配置—Table属性
在上一篇随笔中已经完成了ADO.NET操作数据库的封装,并已经支持多数据库,只需要在配置文件中指定数据库类型即可,本节主要完成对象与数据库表的关系映射配置。 下面看表名的映射配置代码块1-1: [Table(Name="Student")] public class StudentEntity { //...........省略 } 在类上面用[Table(name = ” Student ")]属性来配置,表示该实体类StudentEntity与数据库中的 Student 表进行关系映射。 Table属性需要自己编写,代码块1-2: using System; using System.Collections.Generic; using System.Text; namespace System.Orm.CustomAttributes { [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] public class TableAttribute : Attribute { private string _Name = string.Empty; public TableAttribute() {} public string Name { get { return