Exemplo n.º 1
0
        public virtual ApiResult GetColumns()
        {
            var fields       = Entity <TEntity> .Meta.AllFields;
            var fieldDtoList = new List <TableColumnDto>(fields.Length);

            foreach (var field in fields)
            {
                var fieldDto = new TableColumnDto();
                fieldDto.Copy(field);

                // 处理成小驼峰命名规则
                fieldDto.Name = fieldDto.Name.ToLower()[0].ToString() + fieldDto.Name.Substring(1);

                fieldDtoList.Add(fieldDto);
            }

            return(ApiResult.Ok(fieldDtoList));
        }
Exemplo n.º 2
0
        public virtual ApiResult <List <TableColumnDto> > GetColumns()
        {
            var fields = Entity <TEntity> .Meta.AllFields.Where(
                w => !w.Type.IsGenericType &&
                !typeof(EntityBase).IsAssignableFrom(w.Type) &&
                !w.Type.IsInterface &&
                !w.Type.IsArray
                ).ToList();

            var fieldDtoList = new List <TableColumnDto>(fields.Count);

            foreach (var field in fields)
            {
                var fieldDto = new TableColumnDto();
                fieldDto.Copy(field);

                // 处理成小驼峰命名规则
                // fieldDto.Name = fieldDto.Name.ToLower()[0].ToString() + fieldDto.Name.Substring(1);

                // 非数据库字段设置为只读
                if (field.Field == null)
                {
                    fieldDto.ReadOnly = true;
                }

                if (field.PrimaryKey)
                {
                    fieldDtoList.Insert(0, fieldDto);
                }
                else
                {
                    fieldDtoList.Add(fieldDto);
                }
            }

            return(ApiResult.Ok(fieldDtoList));
        }