标签:
/// <summary> /// 基类,不包含任何字段 /// 如果有自定义主键名对象,请继承此类型 /// </summary> [Serializable] public abstract class IModel : ICloneable
/// <summary> /// 基类,包含Id, AddTime字段 /// </summary> [Serializable] public abstract class IModelBase : IModel { /// <summary> /// 自增主键 /// </summary> [Attribute.Field(PrimaryKey = true)] public int Id { get; set; } private DateTime addTime = DateTime.Now; /// <summary> /// 添加时间 /// </summary> public DateTime AddTime { get { return addTime; } set { addTime = value; } } }
通过此改动,使继承IModel能转化任意类型为CRL操作对象,因此老系统也能进行升级为CRL了
对于自定义主键对象,需指定主键属性
public class Test:CRL.IModel { [CRL.Attribute.Field(PrimaryKey=true)]//指定属性为主键 public int Key2 { get;set; } }
[CRL.Attribute.Field(VirtualField = "year(AddTime)")] public string Year { get; set; } public DateTime AddTime { get;set; }
Year属性为虚拟字段,查询时会按year(AddTime)结果映射
public class ClassA : CRL.IModelBase { public string DataType { get; set; } } public class ClassB:ClassA { public new int DataType { get; set; } }
ClassB继承ClassA,对象将按int DateType 映射
新DLL已打包在示例中,点击下载
标签:
原文地址:http://www.cnblogs.com/hubro/p/4210839.html