예제 #1
0
        /// <summary>
        /// 通用查询方法
        /// </summary>
        /// <typeparam name="T">dto类</typeparam>
        /// <typeparam name="F">dto类下的Data类</typeparam>
        /// <param name="dto"></param>
        /// <returns></returns>
        public ObjectResult GetTableDto <T, F>(GetTableDataDto dto) where T : class, BaseData <T, F>, new() where F : class, BaseParent, new()
        {
            TableHead th = _context.TableHead.Where(x => x.Id == dto.Id).FirstOrDefault();

            if (th == null)
            {
                T entity = new T()
                {
                    TableName = dto.TableName
                };

                List <F> lst = new List <F>();
                for (int i = 0; i < dto.InstanceCount; i++)
                {
                    F s = new F();
                    lst.Add(s);
                }
                entity.Data = lst;
                return(Ok(new { code = 0, msg = "", data = entity, postion = GetPostion(dto.TableName) }));
            }
            else
            {
                var entity = _mapper.Map <T>(th);
                var lst    = _helper.Quyery <F>(x => x.TableHeadId == th.Id).ToList();
                entity.Data = lst;
                return(Ok(new { code = 0, msg = "", data = entity, postion = GetPostion(dto.TableName) }));
            }
        }
예제 #2
0
        public ObjectResult GetTableKeys(string tableName)
        {
            var              defaultNameSpace = Configuration.GetSection("defaultNamespace").Value;
            TableHead        th       = new TableHead();
            List <SelectDto> keys     = new List <SelectDto>();
            var              relation = _context.Relation.Where(x => x.TableName == tableName).FirstOrDefault();

            if (relation == null)
            {
                return(Ok(new { code = 1, msg = "表名不存在,请检查对应表" }));
            }
            var typeName = (relation.DtoNameSpace.IsNullOrEmpty() ? defaultNameSpace : relation.DtoNameSpace) + "." + relation.TableDtoName;

            GetObjKeys(typeName, keys);
            return(Ok(new { code = 0, msg = "", data = keys }));
        }