Oql实体转自定义对象
返回单体:
GroupEnvironmentDTO 是自定义的一个DTO,
GroupEnvironmentEntity.MapToPOCO(dto); 把上述查出来的对象转换为DTO
返回实体集合:(如果把实体本身当做一个集合的话,前台接受出来的json数据,虽然
数据正确,但是格式看起来不太爽)
涉及的dll包
using PWMIS.DataMap.Entity; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using PWMIS.Core.Extensions; using PWMIS.DataProvider.Data; using PWMIS.DataProvider.Adapter; using TransferRepository.Entitys; using TransferRepository; using System.Net; using Newtonsoft.Json; using System.IO; using AuditWorkRepository.Entitys.EntityDTO; using AuditWorkBLL; using System.Configuration; using System.Net.Http; using System.Net.Http.Headers; using A1000;
注: list是上述oql查询出来的结果集,AuditProceDureDTO是自定义的一个类,
item1 是集合中的实体对象,
item1.MapToPOCO(proDTO)
listpro是一个自定的 List<AuditProcedureDTO> listpro =new List<AuditProcedureDTO>();
循环的过程中添加完,最后返回一个集合就ok了, 这样的话就不会出现奇奇怪怪的json数据了、
(导致出现奇怪的JSON数据,是因为实体中右getProperty(读),setProperty(写)俩个属性导致而成。
所以说尽量不要偷懒,老老实实的定义个临时类)
另外一种查询的方式:
EntityContainer ec = new EntityContainer(t, db); dto = ec.MapToList<ScriptDTO>(() => new ScriptDTO() { Name = item.ManuscriptName, WhetherGroup = work.WhetherGroup }).FirstOrDefault();
下方就是不转自定义类 返回的数据结果
多条件查询:
OQLCompareFunc cmpFun = cmp => { #region OQLCompare cmpResult = new OQLCompare(); cmpResult = cmpResult & cmp.Comparer(poj.TerminationProject, "=", Constant.EnableProject) .Comparer(poj.ID, "in", listguid.ToArray()); #endregion #region 检索条件 if (!string.IsNullOrEmpty(AuditProjectQueryCriteria.ProjectName)) { cmpResult = cmpResult & cmp.Comparer(poj.ProjectName, "like", "%" + AuditProjectQueryCriteria.ProjectName + "%"); //项目名称 } if (AuditProjectQueryCriteria.RiskLevel > 0) { cmpResult = cmpResult & cmp.Comparer(poj.RiskLevel, "=", AuditProjectQueryCriteria.RiskLevel); //风险等级 } if (AuditProjectQueryCriteria.IndustryType > 0) { cmpResult = cmpResult & cmp.Comparer(poj.IndustryType, "=", AuditProjectQueryCriteria.IndustryType); //行业类型 } if (AuditProjectQueryCriteria.IsHeadquartersReview > 0) { cmpResult = cmpResult & cmp.Comparer(poj.IsHeadquartersReview, "=", AuditProjectQueryCriteria.IsHeadquartersReview); //是否复核总部 } if (!string.IsNullOrEmpty(AuditProjectQueryCriteria.AuditStartDate)) { cmpResult = cmpResult & cmp.Comparer(poj.AuditStartDate, ">", Convert.ToDateTime(AuditProjectQueryCriteria.AuditStartDate)); //开始时间 } if (!string.IsNullOrEmpty(AuditProjectQueryCriteria.AuditEndDate)) { cmpResult = cmpResult & cmp.Comparer(poj.AuditEndDate, "<", Convert.ToDateTime(AuditProjectQueryCriteria.AuditEndDate)); //结束 } if (AuditProjectQueryCriteria.ManuscriptTemplateName != null) { cmpResult = cmpResult & cmp.Comparer(poj.ManuscriptTemplateName, "like", "%" + AuditProjectQueryCriteria.ManuscriptTemplateName + "%");//底稿名称 } if (AuditProjectQueryCriteria.NoteAppendedTypeName != null) { cmpResult = cmpResult & cmp.Comparer(poj.NoteAppendedTypeName, "like", "%" + AuditProjectQueryCriteria.NoteAppendedTypeName + "%"); //附注名称 } if (!string.IsNullOrEmpty(AuditProjectQueryCriteria.ProjectCreateDate)) { cmpResult = cmpResult & cmp.Comparer(poj.ProjectCreateDate, "=", Convert.ToDateTime(AuditProjectQueryCriteria.ProjectCreateDate)); //附注名称 } if (!string.IsNullOrEmpty(AuditProjectQueryCriteria.ManagerProjectName)) { cmpResult = cmpResult & cmp.Comparer(poj.ManagerProjectName, "=", AuditProjectQueryCriteria.ManagerProjectName); //被审计单位名称 } if (AuditProjectQueryCriteria.SubmitState > 0) { cmpResult = cmpResult & cmp.Comparer(poj.SubmitState, "=", AuditProjectQueryCriteria.SubmitState); //状态 } #endregion return cmpResult; };
链接字符串:
public AuditworkProjectBll(string dbname) { context = new AuditWorkDbContext(dbname); db = context.CurrentDataBase; pbll = new AuditPlanBLL(dbname); docbll = new DockingClassBll(dbname); } private AuditWorkDbContext context;// 数据上下文 private AdoHelper db; AuditPlanBLL pbll = null; AdoHelper db1 = MyDB.GetDBHelperByConnectionName("AuditManage"); DockingClassBll docbll = null; AdoHelper asd = MyDB.GetDBHelperByConnectionName("Transfer");