Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public static string TableNameFromTypeRow(Type typeRow)
        {
            SqlNameAttribute attributeRow = (SqlNameAttribute)typeRow.GetTypeInfo().GetCustomAttribute(typeof(SqlNameAttribute));

            return(attributeRow.SqlName);
        }