예제 #1
0
        public override async Task <EasyDataResultSet> GetEntitiesAsync(string modelId, string entityContainer,
                                                                        string filter = null, bool isLookup = false, int?offset = null, int?fetch = null)
        {
            await GetModelAsync(modelId);

            var entityType = GetCurrentEntityType(DbContext, entityContainer);
            var entities   = await ListAllEntitiesAsync(DbContext, entityType.ClrType, filter, isLookup, offset, fetch);

            var result = new EasyDataResultSet();

            var props = entityType.GetProperties();

            foreach (var prop in props)
            {
                result.cols.Add(new EasyDataCol(
                                    DataUtils.ComposeKey(entityType.Name.Split('.').Last(), prop.Name),
                                    DataUtils.PrettifyName(prop.Name),
                                    DataUtils.GetDataTypeBySystemType(prop.ClrType)));
            }

            foreach (var entity in entities)
            {
                result.rows.Add(new EasyDataRow(props.Select(prop => prop.PropertyInfo.GetValue(entity)).ToList()));
            }

            return(result);
        }
예제 #2
0
        public override async Task <EasyDataResultSet> GetEntitiesAsync(string modelId, string entityContainer, IEnumerable <EasyFilter> filters = null, bool isLookup = false, int?offset = null, int?fetch = null, CancellationToken ct = default)
        {
            if (filters == null)
            {
                filters = Enumerable.Empty <EasyFilter>();
            }

            await GetModelAsync(modelId);

            var entityType = GetCurrentEntityType(DbContext, entityContainer);
            var entities   = await ListAllEntitiesAsync(DbContext, entityType.ClrType, filters, isLookup, offset, fetch, ct);

            var result = new EasyDataResultSet();

            var props = entityType.GetProperties();

            foreach (var prop in props)
            {
                var attrId = DataUtils.ComposeKey(entityType.Name.Split('.').Last(), prop.Name);
                var attr   = Model.FindEntityAttr(attrId);
                result.Cols.Add(new EasyDataCol(new EasyDataColDesc {
                    Id            = attrId,
                    Label         = DataUtils.PrettifyName(prop.Name),
                    AttrId        = attr?.Id,
                    DisplayFormat = attr?.DisplayFormat,
                    Type          = attr != null ? attr.DataType :DataUtils.GetDataTypeBySystemType(prop.ClrType)
                }));
            }

            foreach (var entity in entities)
            {
                result.Rows.Add(new EasyDataRow(props.Select(prop => prop.PropertyInfo.GetValue(entity)).ToList()));
            }

            return(result);
        }