private static IQueryable SelectQuery(Type typeRow) { var conventionBuilder = new CoreConventionSetBuilder(); var conventionSet = conventionBuilder.CreateConventionSet(); var builder = new ModelBuilder(conventionSet); { var entity = builder.Entity(typeRow); SqlNameAttribute attributeRow = (SqlNameAttribute)typeRow.GetTypeInfo().GetCustomAttribute(typeof(SqlNameAttribute)); entity.ToTable(attributeRow.SqlName); foreach (PropertyInfo propertyInfo in typeRow.GetTypeInfo().GetProperties()) { SqlNameAttribute attributeProperty = (SqlNameAttribute)propertyInfo.GetCustomAttribute(typeof(SqlNameAttribute)); entity.Property(propertyInfo.PropertyType, propertyInfo.Name).HasColumnName(attributeProperty.SqlName); } } var options = new DbContextOptionsBuilder <DbContext>(); options.UseSqlServer(Framework.Server.ConnectionManager.ConnectionString); options.UseModel(builder.Model); DbContext dbContext = new DbContext(options.Options); dbContext.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; // For SQL views. No primary key. IQueryable query = (IQueryable)(dbContext.GetType().GetTypeInfo().GetMethod("Set").MakeGenericMethod(typeRow).Invoke(dbContext, null)); return(query); }
public static List <Cell> ColumnList(Type typeRow) { List <Cell> result = new List <Cell>(); SqlNameAttribute attributeRow = (SqlNameAttribute)typeRow.GetTypeInfo().GetCustomAttribute(typeof(SqlNameAttribute)); foreach (PropertyInfo propertyInfo in typeRow.GetTypeInfo().GetProperties()) { SqlNameAttribute attributePropertySql = (SqlNameAttribute)propertyInfo.GetCustomAttribute(typeof(SqlNameAttribute)); TypeCellAttribute attributePropertyCell = (TypeCellAttribute)propertyInfo.GetCustomAttribute(typeof(TypeCellAttribute)); Cell cell = (Cell)Activator.CreateInstance(attributePropertyCell.TypeCell); cell.Constructor(attributeRow.SqlName, attributePropertySql.SqlName, propertyInfo.Name); result.Add(cell); } return(result); }
public static string TableNameFromTypeRow(Type typeRow) { SqlNameAttribute attributeRow = (SqlNameAttribute)typeRow.GetTypeInfo().GetCustomAttribute(typeof(SqlNameAttribute)); return(attributeRow.SqlName); }