private static string GetPrimaryKeyName(Type type)
        {
            System.Reflection.PropertyInfo[] arrProperty = type.GetProperties();
            string result;

            for (int i = 0; i < arrProperty.Length; i++)
            {
                System.Reflection.PropertyInfo propertyInfo = arrProperty[i];
                if (propertyInfo.IsPrimaryKey())
                {
                    result = propertyInfo.Name;
                    return(result);
                }
            }
            arrProperty = type.GetProperties();
            for (int i = 0; i < arrProperty.Length; i++)
            {
                System.Reflection.PropertyInfo propertyInfo = arrProperty[i];
                if (propertyInfo.Name.ToLower() == "id")
                {
                    result = propertyInfo.Name;
                    return(result);
                }
            }
            result = type.Name + "Id";
            return(result);
        }
Ejemplo n.º 2
0
 public static System.Reflection.PropertyInfo GetPrimaryKeyInfo(System.Type modelType)
 {
     System.Reflection.PropertyInfo[] properties = modelType.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
     System.Reflection.PropertyInfo   result;
     for (int i = 0; i < properties.Length; i++)
     {
         System.Reflection.PropertyInfo propertyInfo = properties[i];
         if (propertyInfo.IsPrimaryKey())
         {
             result = propertyInfo;
             return(result);
         }
     }
     result = null;
     return(result);
 }