Ejemplo n.º 1
0
 /// <summary>
 /// 获取主键名
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public static string GetPrimary(Type type)
 {
     object[] attributes = type.GetCustomAttributes(false);
     foreach (var attr in attributes)
     {
         if (attr is PrimaryKeyAttribute)
         {
             PrimaryKeyAttribute primaryKeyAttr = attr as PrimaryKeyAttribute;
             return(primaryKeyAttr.Value);
         }
     }
     return(null);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 判断主键是否自增
 /// </summary>
 /// <param name="property"></param>
 /// <returns></returns>
 public static bool IsIncrement(Type type)
 {
     object[] attributes = type.GetCustomAttributes(false);
     foreach (var attr in attributes)
     {
         if (attr is PrimaryKeyAttribute)
         {
             PrimaryKeyAttribute primaryKeyAttr = attr as PrimaryKeyAttribute;
             return(primaryKeyAttr.autoIncrement);
         }
     }
     return(false);
 }