Exemplo n.º 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) }));
            }
        }
Exemplo n.º 2
0
        public object GetData(int id, string tableName)
        {
            var defaultNameSpace = Configuration.GetSection("defaultNamespace").Value;
            var rel = _context.Relation.Where(x => x.TableName == tableName).FirstOrDefault();

            if (rel == null)
            {
                return(Ok(new { code = 1, msg = "表单不存在" }));
            }
            GetTableDataDto entity = new GetTableDataDto()
            {
                Id = id, TableName = tableName, InstanceCount = rel.InstanceCount
            };
            var  dataTypeName = (rel.TableNamespace.IsNullOrEmpty() ? defaultNameSpace : rel.TableNamespace) + "." + rel.TableDtoDataName;
            var  dtoTypeName  = (rel.DtoNameSpace.IsNullOrEmpty() ? defaultNameSpace : rel.DtoNameSpace) + "." + rel.TableDtoName;
            Type t            = Type.GetType(dtoTypeName);
            Type t2           = Type.GetType(dataTypeName);

            Type[] typeArgs = { t, t2 };
            var    result   = this.GetType().GetMethod("GetTableDto").MakeGenericMethod(typeArgs).Invoke(this, new object[] { entity });

            return(result);
        }