/// <summary> /// Initializes a new instance of the <see cref="CRUDControllerBase{T, O}"/> class. /// </summary> /// <param name="repository">A repository object.</param> public CRUDControllerBase(O repository) { _Repository = repository; PrimaryKeyInfo = CRUDModelPKAttribute.GetPKProperty <T>(); CRUDModelPKAttribute att = (CRUDModelPKAttribute)PrimaryKeyInfo.GetCustomAttribute(typeof(CRUDModelPKAttribute)); IsPKAutoIncrement = att.AutoIncrement; }
/// <summary> /// Evaluates if the primary key is an auto increment field. /// </summary> /// <typeparam name="T">The type of the model.</typeparam> public static bool IsAutoGenerated <T>() where T : class, new() { Type type = typeof(T); PropertyInfo[] properties = type.GetProperties(); PropertyInfo property = properties.FirstOrDefault(p => p.GetCustomAttributes(typeof(CRUDModelPKAttribute), false).Any()); if (property != null) { CRUDModelPKAttribute att = (CRUDModelPKAttribute)property.GetCustomAttribute(typeof(CRUDModelPKAttribute)); return(att.AutoIncrement); } return(false); }