/// <summary> /// 获取表名 /// </summary> /// <returns></returns> public string GetTableSql() { StringBuilder sb = new StringBuilder(); string tableName = table; if (string.IsNullOrWhiteSpace(tableName)) { Type type = typeof(T); if (Attribute.GetCustomAttributes(type).Any(x => x is SugarTable)) { SugarTable table = Attribute.GetCustomAttributes(type).FirstOrDefault(x => x is SugarTable) as SugarTable; if (!string.IsNullOrWhiteSpace(table.TableName)) { tableName = table.TableName; } } } if (tableName.IndexOf(Left) == -1) { sb.Append(Left); } sb.Append(tableName); if (tableName.IndexOf(Right) == -1) { sb.Append(Right); } return(sb.ToString()); }
public MtInsertableProvider() { Type t = typeof(T); _tableName = t.Name; SugarTable sugarTable = t.GetAttributeInfo<SugarTable>(); if (sugarTable != null) { if (!string.IsNullOrWhiteSpace(sugarTable.TableName)) { _tableName = sugarTable.TableName; } } _dbColumnInfos = new List<DbColumnInfo>(); _dbColumnInfos.ConcatWith(t.GetProperties(), prop => { SugarColumn sugarColumn = prop.GetAttributeInfo<SugarColumn>(); if (sugarColumn != null) { return !sugarColumn.IsOnlyIgnoreInsert; } return true; }, (column, prop) => { column.DbColumnName = prop.Name; column.PropertyName = prop.Name; column.PropertyType = prop.PropertyType; SugarColumn sugarColumn = prop.GetAttributeInfo<SugarColumn>(); if (sugarColumn != null) { column.DbColumnName = sugarColumn.ColumnName; } }); }