internal static EntityTable ToEntityTable(Type type) { var table = TryGetTable(type); if (table.Name != null) { return(table); // have table in cache } // get properties add to cache var properties = new SortedDictionary <string, EntityColumn>(); type.GetProperties() .Where(p => !Attribute.IsDefined(p, typeof(NotMappedAttribute))) .ToList() .ForEach( x => { var col = (ColumnAttribute)x.GetCustomAttribute(typeof(ColumnAttribute)); var dbgen = (DatabaseGeneratedAttribute)x.GetCustomAttribute(typeof(DatabaseGeneratedAttribute)); properties.Add(x.Name, new EntityColumn() { CSharpName = x.Name, ColumnName = (col != null) ? col.Name : x.Name, PrimaryKey = Attribute.IsDefined(x, typeof(KeyAttribute)), ForeignKey = Attribute.IsDefined(x, typeof(ForeignKeyAttribute)), GeneratedOption = dbgen == null?DatabaseGeneratedOption.None: dbgen.DatabaseGeneratedOption, }); } ); var attrib = (TableAttribute)type.GetCustomAttribute(typeof(TableAttribute)); table = new EntityTable { Name = (attrib != null ? attrib.Name : type.Name), Columns = properties, Identifier = $"t{Size + 1}" }; TryAddTable(type, table); return(table); }
internal static bool TryAddTable(Type type, EntityTable entityTable) { return(TypeList.TryAdd(type, entityTable)); }
internal static bool TryAddTable <T>(EntityTable entityTable) { return(TryAddTable(typeof(T), entityTable)); }