/// <summary> /// 更新缓存 /// </summary> /// <typeparam name="T"></typeparam> private static ModelDes UpdateModelDesCache <T>() { var type = typeof(T); var cacheValue = ExistModelDesCache(type.FullName); if (cacheValue == null) { var model = new ModelDes(); #region 表描述 model.ClassType = type; model.ClassName = type.Name; var tbAttrObj = type.GetCustomAttributes(typeof(TableAttribute), true).FirstOrDefault(); if (tbAttrObj != null) { var tbAttr = tbAttrObj as TableAttribute; if (!string.IsNullOrEmpty(tbAttr.Name)) { model.TableName = tbAttr.Name; } else { model.TableName = model.ClassName; } } else { model.TableName = model.ClassName; } #endregion #region 属性描述 foreach (var propertyInfo in type.GetProperties()) { var pty = new PropertyDes(); pty.Field = propertyInfo.Name; var arri = propertyInfo.GetCustomAttributes(typeof(BaseAttribute), true).FirstOrDefault(); if (arri is IgnoreAttribute) { continue; } else if (arri is IdAttribute) { pty.CusAttribute = arri as IdAttribute; } else if (arri is ColumnAttribute) { pty.CusAttribute = arri as ColumnAttribute; } model.Properties.Add(pty); } #endregion Add(type.FullName, model); cacheValue = model; } return(cacheValue); }
/// <summary> /// 获取对象的主键标识列和属性(多主键的) /// </summary> /// <param name="des"></param> /// <returns></returns> internal static List <PropertyDes> GetPrimarys(ModelDes des) { List <PropertyDes> ret = new List <PropertyDes>(); var pList = des.Properties.Where(m => m.CusAttribute is KeyAttribute); foreach (PropertyDes p in pList) { PropertyDes pd = p as PropertyDes; ret.Add(pd); } if (ret.Count <= 0) { throw new Exception("没有任何列标记为主键特性"); } return(ret); }