/// <inheritdoc/> public IHasDependencies[] GetObjectsDependingOnThis() { return(ColumnInfos.ToArray()); }
/// <summary> /// 判定是否有了对应列 /// </summary> /// <param name="columnKey"></param> /// <returns></returns> public bool HaveColumn(string columnKey) => ColumnInfos != null && ColumnInfos.Count(o => o.ColumnKey == columnKey) > 0;
/// <summary> /// /// </summary> /// <param name="type"></param> /// <param name="tablenameMapper"></param> public TableInfo(Type type) { ClassType = type; //NOTE: This as dynamic trick should be able to handle both our own Table-attribute as well as the one in EntityFramework var tableAttr = type .GetCustomAttributes(false).SingleOrDefault(attr => attr.GetType().Name == "TableAttribute") as dynamic; if (tableAttr != null) { TableName = tableAttr.Name; if ((!(tableAttr is TableAttribute)) && tableAttr.Schema != null) { SchemaName = tableAttr.Schema; } } else { TableName = type.Name; if (type.IsInterface() && TableName.StartsWith("I")) { TableName = TableName.Substring(1); } } ColumnInfos = type.GetProperties() .Where(t => t.GetCustomAttributes(typeof(IgnoreAttribute), false).Count() == 0) .Select(t => { var columnAtt = t.GetCustomAttributes(false).SingleOrDefault(attr => attr.GetType().Name == "ColumnAttribute") as dynamic; var ci = new ColumnInfo { Property = t, ColumnName = columnAtt?.Name ?? t.Name, PropertyName = t.Name, IsKey = t.GetCustomAttributes(true).Any(a => a is KeyAttribute), IsIdentity = t.GetCustomAttributes(true).Any(a => a is DatabaseGeneratedAttribute && (a as DatabaseGeneratedAttribute).DatabaseGeneratedOption == DatabaseGeneratedOption.Identity), IsGenerated = t.GetCustomAttributes(true).Any(a => a is DatabaseGeneratedAttribute && (a as DatabaseGeneratedAttribute).DatabaseGeneratedOption != DatabaseGeneratedOption.None), ExcludeOnSelect = t.GetCustomAttributes(true).Any(a => a is IgnoreSelectAttribute) }; ci.ExcludeOnInsert = ci.IsGenerated || t.GetCustomAttributes(true).Any(a => a is IgnoreInsertAttribute) || t.GetCustomAttributes(true).Any(a => a is ReadOnlyAttribute); ci.ExcludeOnUpdate = ci.IsGenerated || t.GetCustomAttributes(true).Any(a => a is IgnoreUpdateAttribute) || t.GetCustomAttributes(true).Any(a => a is ReadOnlyAttribute); return(ci); }) .ToArray(); if (!ColumnInfos.Any(k => k.IsKey)) { var idProp = ColumnInfos.FirstOrDefault(p => string.Equals(p.PropertyName, "id", StringComparison.CurrentCultureIgnoreCase)); if (idProp != null) { idProp.IsKey = idProp.IsGenerated = idProp.IsIdentity = idProp.ExcludeOnInsert = idProp.ExcludeOnUpdate = true; } } }
public void AddColumn(int index, string columnName, string columnType) { ColumnInfos.Add(new ColumnInfo { Index = index, ColumnName = columnName, ColumnType = columnType }); }
private List <IDataTableColumnInfo> GetDataBoundColumnInfos() { return(ColumnInfos.Where(c => GetModelProperties() .Where(p => p.IsDataBound()).Select(p => p.Name).Contains(c.Data)).ToList()); }