public void GetTableInfo(Type t, TableInfo ti) { var mapper = GetMapper(t); if (mapper != null) mapper.GetTableInfo(t, ti); }
public void GetTableInfo(Type t, TableInfo ti) { var tableSchema = this._schemaProvider.GetSchema(t); if (tableSchema != null) { ti.AutoIncrement = tableSchema.HasAutoIncrement; ti.PrimaryKey = tableSchema.PrimaryKey; ti.TableName = tableSchema.TableName; } }
public static TableInfo FromPoco(System.Type t) { TableInfo tableInfo = new TableInfo(); object[] customAttributes = t.GetCustomAttributes(typeof(TableNameAttribute), true); tableInfo.TableName = ((customAttributes.Length == 0) ? t.Name : (customAttributes[0] as TableNameAttribute).Value); customAttributes = t.GetCustomAttributes(typeof(PrimaryKeyAttribute), true); tableInfo.PrimaryKey = ((customAttributes.Length == 0) ? "ID" : (customAttributes[0] as PrimaryKeyAttribute).Value); tableInfo.SequenceName = ((customAttributes.Length == 0) ? null : (customAttributes[0] as PrimaryKeyAttribute).sequenceName); tableInfo.AutoIncrement = (customAttributes.Length != 0 && (customAttributes[0] as PrimaryKeyAttribute).autoIncrement); return tableInfo; }
public TableInfo GetTableInfo(Type pocoType) { //Table Name TableInfo table = new TableInfo(); table.TableName = Util.GetTableName(pocoType, table.TableName + "s"); table.TableName = _tablePrefix + table.TableName; //Primary Key table.PrimaryKey = Util.GetPrimaryKeyName(pocoType); table.AutoIncrement = true; return table; }
/// <summary> /// Creates and populates a TableInfo from the attributes of a POCO /// </summary> /// <param name="t">The POCO type</param> /// <returns>A TableInfo instance</returns> public static TableInfo FromPoco(Type t) { TableInfo ti = new TableInfo(); // Get the table name var a = t.GetCustomAttributes(typeof(TableNameAttribute), true); ti.TableName = a.Length == 0 ? t.Name : (a[0] as TableNameAttribute).Value; // Get the primary key a = t.GetCustomAttributes(typeof(PrimaryKeyAttribute), true); ti.PrimaryKey = a.Length == 0 ? "ID" : (a[0] as PrimaryKeyAttribute).Value; ti.SequenceName = a.Length == 0 ? null : (a[0] as PrimaryKeyAttribute).sequenceName; ti.AutoIncrement = a.Length == 0 ? false : (a[0] as PrimaryKeyAttribute).autoIncrement; return ti; }
/// <summary> /// Creates and populates a TableInfo from the attributes of a POCO /// </summary> /// <param name="t">The POCO type</param> /// <returns>A TableInfo instance</returns> public static TableInfo FromPoco(Type t) { TableInfo ti = new TableInfo(); // Get the table name var a = t.GetCustomAttributes(typeof(TableNameAttribute), true); ti.TableName = a.Length == 0 ? t.Name : (a[0] as TableNameAttribute).Value; // Get the primary key a = t.GetCustomAttributes(typeof(PrimaryKeyAttribute), true); ti.PrimaryKey = a.Length == 0 ? null : (a[0] as PrimaryKeyAttribute).Value; ti.SequenceName = a.Length == 0 ? null : (a[0] as PrimaryKeyAttribute).SequenceName; ti.AutoIncrement = a.Length == 0 ? false : (a[0] as PrimaryKeyAttribute).AutoIncrement; if (string.IsNullOrEmpty(ti.PrimaryKey)) { var prop = t.GetProperties().FirstOrDefault(p => { if (p.Name.Equals("id", StringComparison.OrdinalIgnoreCase)) return true; if (p.Name.Equals(t.Name + "id", StringComparison.OrdinalIgnoreCase)) return true; if (p.Name.Equals(t.Name + "_id", StringComparison.OrdinalIgnoreCase)) return true; return false; }); if (prop != null) { ti.PrimaryKey = prop.Name; ti.AutoIncrement = prop.PropertyType.IsValueType; } } return ti; }
/// <summary> /// Get information about the table associated with a POCO class /// </summary> /// <param name="pocoType">The poco type.</param> /// <returns>A TableInfo instance</returns> /// <remarks> /// This method must return a valid TableInfo. /// To create a TableInfo from a POCO's attributes, use TableInfo.FromPoco /// </remarks> public TableInfo GetTableInfo(Type pocoType) { var ti = new TableInfo(); return MapTable(ti, pocoType) ? ti : null; }
public abstract void GetTableInfo(Type t, TableInfo ti);