コード例 #1
0
        public TableViewModel DataAsTableViewModel <T>(List <T> datas, int Page, int Rows, int RecordCount, params Type[] EntityTypes)
        {
            TableViewModel _tableViewModel = new TableViewModel();

            _tableViewModel.Page       = Page;
            _tableViewModel.Rows       = Rows;
            _tableViewModel.TotalCount = RecordCount;
            _tableViewModel.TotalPage  = (RecordCount / Rows);
            //DynamicQueryable.OrderBy(query, "name asc");


            var type   = typeof(T);
            var fields = type.GetProperties();

            #region 组合一下 类型的属性和类型名称
            var TabAndField = new List <(string, string)>();
            foreach (var item in EntityTypes)
            {
                foreach (var prop in item.GetProperties())
                {
                    TabAndField.Add((prop.Name, item.Name));
                }
            }
            #endregion

            #region 填充 列 信息

            foreach (var field in fields)
            {
                var tableName = TabAndField.Find(w => w.Item1 == field.Name).Item2;

                var title = string.Empty;

                if (!string.IsNullOrWhiteSpace(tableName))
                {
                    var modelInfos = ModelCache.GetModelInfos(tableName);
                    title = modelInfos.FirstOrDefault(w => w.Name == field.Name)?.Remark;
                }

                _tableViewModel.Cols.Add(new TableViewCol()
                {
                    DataIndex = field.Name,
                    Show      = field.Name != "_ukid",
                    Title     = string.IsNullOrWhiteSpace(title) ? field.Name : title
                });
            }
            #endregion
            #region 和数据转换为 list Hashtable
            foreach (var item in datas)
            {
                var hashTable = new Hashtable();
                foreach (var field in fields)
                {
                    hashTable[field.Name] = field.GetValue(item);
                }
                _tableViewModel.DataSource.Add(hashTable);
            }
            #endregion
            return(_tableViewModel);
        }
コード例 #2
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity <TABLES_COLUMNS>().HasNoKey();
            modelBuilder.Entity <TABLE_NAME>().HasNoKey();
            //
            //modelBuilder.Entity<Sys_AppLog>().ToTable("Sys_AppLog");
            //modelBuilder.Entity<User>().ToTable("User");

            #region 扫描表 并 缓存 属性信息
            var types = modelBuilder.Model.GetEntityTypes().Select(item => item.ClrType).ToList();
            ModelCache.Set(types);
            #endregion
        }