コード例 #1
0
        /// <summary>
        /// 通过主键获取一条记录(不含已删除)

        /// 日期:2016年7月29日
        /// </summary>
        /// <param name="ID">主键</param>
        /// <returns></returns>
        public virtual TEntity Single(string ID, List <Expression <Func <TEntity, object> > > includes = null)
        {
            if (_PK.Count <= 0)
            {
                throw new Exception("没有设置主键");
            }

            if (_PK.Count > 1)
            {
                throw new Exception("不支持复合主键");
            }

            using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities())
            {
                IQueryable <TEntity> cities = db.Set <TEntity>();
                ParameterExpression  param  = Expression.Parameter(typeof(TEntity), "TEntity");
                Expression           left   = Expression.Property(param, typeof(TEntity).GetProperty(_PK[0]));
                Expression           right  = Expression.Constant(ID);
                Expression           filter = Expression.Equal(left, right);
                var query = db.Set <TEntity>().Where(Expression.Lambda <Func <TEntity, bool> >(filter, param)).Where(a => a.IsDeleted == false);

                if (includes != null)
                {
                    query = includes.Aggregate(query, (current, include) => current.Include(include));
                }

                var result = query.SingleOrDefault();

                return(result);
            }
        }
コード例 #2
0
        /// <summary>
        /// 获取分页(不含已删除)

        /// 日期:2016年7月29日
        /// </summary>
        /// <typeparam name="TResult">返回结果类型</typeparam>
        /// <typeparam name="TKey">排序类型</typeparam>
        /// <param name="where">插叙条件</param>
        /// <param name="orderBy">排序</param>
        /// <param name="select">返回结果映射</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">分页大小</param>
        /// <returns></returns>
        public virtual List <TResult> Select <TResult>(
            out int totalCount,
            int?PageIndex = 0,
            int?PageSize  = 10,
            List <Expression <Func <TEntity, object> > > includes = null,
            Expression <Func <TEntity, bool> > where       = null,
            Expression <Func <TEntity, object> > orderBy   = null,
            Expression <Func <TEntity, TResult> > selector = null)
            where TResult : class
        {
            using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities())
            {
                List <TEntity> result = new List <TEntity>();

                var query = db.Set <TEntity>().AsQueryable().Where(a => a.IsDeleted == false);

                if (includes != null)
                {
                    query = includes.Aggregate(query, (current, include) => current.Include(include));
                }

                #region 增加查询条件
                if (where != null)
                {
                    query = db.Set <TEntity>().Where(where);
                }
                #endregion

                #region 设置排序
                if (orderBy != null)
                {
                    query = query.OrderByDescending(orderBy);
                }
                else
                {
                    query = query.OrderByDescending(a => a.CreateTime);
                }

                #endregion

                #region 设置分页
                if (PageSize.HasValue && PageIndex.HasValue)
                {
                    var fTotal = query.FutureCount();
                    var fList  = query.Skip((PageIndex.Value - 1) * PageSize.Value).Take(PageSize.Value).Select(selector).Future();
                    totalCount = fTotal.Value;
                    return(fList.ToList());
                }
                else
                {
                    var fTotal = query.FutureCount();
                    var fList  = query.Select(selector).Future();
                    totalCount = fTotal.Value;
                    return(fList.ToList());
                }
                #endregion
            }
        }
コード例 #3
0
 /// <summary>
 /// 获取记录数(不含已删除)
 /// 作者:曾璐
 /// </summary>
 /// <param name="where">查询条件</param>
 /// <returns></returns>
 public int Count(Expression <Func <TEntity, bool> > where)
 {
     using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities())
     {
         return(db.Set <TEntity>().Where(where).Where(a => a.IsDeleted == false).Count());
     }
 }
コード例 #4
0
        /// <summary>
        /// 通过表达式删除记录(物理删除)

        /// 日期:2016年7月29日
        /// </summary>
        /// <param name="where">查询条件</param>
        /// <returns></returns>
        public bool Delete(Expression <Func <TEntity, bool> > where)
        {
            using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities())
            {
                return(db.Set <TEntity>().Where(where).Delete() > 0 ? true : false);
            }
        }
コード例 #5
0
        /// <summary>
        /// 更新一条记录(部分更新)

        /// 日期:2016年7月29日
        /// </summary>
        /// <param name="updateExpress">更新表达式)</param>
        /// <returns></returns>
        public virtual bool Update(Expression <Func <TEntity, bool> > where, Expression <Func <TEntity, TEntity> > updateExpress)
        {
            using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities())
            {
                return(db.Set <TEntity>().Where(where).Update(updateExpress) > 0 ? true : false);
            }
        }
コード例 #6
0
        public Response <List <DTO.ConversationMessageReturnDTO> > GetMessages(int ChannelID, int CurrentPage, int PageSize)
        {
            using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities())
            {
                int totalCount = 0;
                Response <List <DTO.ConversationMessageReturnDTO> > result = new Response <List <DTO.ConversationMessageReturnDTO> >();

                var query = from message in db.Set <ConversationMessage>().AsQueryable().Where(a => a.IsDeleted == false)
                            where message.ConversationRoomID == ChannelID
                            group message by message.MessageSeq into gps
                            select new DTO.ConversationMessageReturnDTO()
                {
                    MsgSeq      = gps.Key,
                    FromAccount = gps.FirstOrDefault().UserID,
                    ToGroupId   = gps.FirstOrDefault().ConversationRoomID.ToString(),
                    MsgTime     = gps.FirstOrDefault().MessageTime,
                    MsgBody     = gps.OrderBy(a => a.MessageIndex).Select(a => a.MessageContent).ToList(),
                };

                query = query.OrderBy(a => new { a.MsgTime });


                var fTotal = query.FutureCount();
                var fList  = query.Skip((CurrentPage - 1) * PageSize).Take(PageSize).Future();
                totalCount   = fTotal.Value;
                result.Data  = fList.ToList();
                result.Total = totalCount;

                return(result);
            }
        }
コード例 #7
0
        /// <summary>
        /// 获取患者历史就诊记录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public Response <List <DTO.UserOPDRegisterDTO> > GetPatientVisitList(string OPDRegisterID, string MemberID, int PageIndex, int PageSize)
        {
            using (DAL.EF.DBEntities db = new DAL.EF.DBEntities())
            {
                var query = from opd in db.Set <UserOPDRegister>().Where(a => a.IsDeleted == false && (a.OPDRegisterID != OPDRegisterID || string.IsNullOrEmpty(OPDRegisterID)) && a.MemberID == MemberID)
                            join room in db.Set <Entity.ConversationRoom>() on opd.OPDRegisterID equals room.ServiceID
                            join medi in db.Set <UserMedicalRecord>().Where(a => a.IsDeleted == false && a.MemberID == MemberID) on opd.OPDRegisterID equals medi.OPDRegisterID into medileftjoin
                            from mediifEmpty in medileftjoin.DefaultIfEmpty()
                            join doctor in db.Set <XuHos.Entity.Doctor>().Where(a => a.IsDeleted == false) on opd.DoctorID equals doctor.DoctorID
                            join dept in db.Set <HospitalDepartment>().Where(a => a.IsDeleted == false) on doctor.DepartmentID equals dept.DepartmentID
                            join hosp in db.Set <Hospital>().Where(a => a.IsDeleted == false) on doctor.HospitalID equals hosp.HospitalID
                            orderby room.BeginTime descending
                            select new DTO.UserOPDRegisterDTO
                {
                    OPDRegisterID = opd.OPDRegisterID,
                    RegDate       = opd.RegDate,
                    OPDDate       = opd.OPDDate,
                    OPDType       = opd.OPDType,
                    OPDBeginTime  = opd.OPDBeginTime,
                    OPDEndTime    = opd.OPDEndTime,
                    Room          = new DTO.ConversationRoomDTO()
                    {
                        TotalTime     = room.TotalTime,
                        Enable        = room.Enable,
                        Duration      = room.Duration,
                        ChargingState = room.ChargingState,
                        RoomState     = room.RoomState,     //状态
                        ChannelID     = room.ChannelID,     //房间号码
                        EndTime       = room.EndTime,       //结束时间
                        Priority      = room.Priority
                    },
                    UserMedicalRecord = new UserMedicalRecordDTO()
                    {
                        PastMedicalHistory    = mediifEmpty.PastMedicalHistory,
                        PreliminaryDiagnosis  = mediifEmpty.PreliminaryDiagnosis,
                        PresentHistoryIllness = mediifEmpty.PresentHistoryIllness,
                        Sympton         = mediifEmpty.Sympton,
                        Advised         = mediifEmpty.Advised,
                        AllergicHistory = mediifEmpty.AllergicHistory
                    },
                    Doctor = new DTO.DoctorDto()
                    {
                        DoctorName     = doctor.DoctorName,
                        DepartmentName = doctor.DepartmentName,
                        DoctorID       = doctor.DoctorID,
                        DepartmentID   = doctor.DepartmentID,
                        HospitalID     = hosp.HospitalID,
                        HospitalName   = hosp.HospitalName
                    }
                };

                query = query.OrderByDescending(t => t.OPDDate);

                Response <List <DTO.UserOPDRegisterDTO> > result = new Response <List <DTO.UserOPDRegisterDTO> >();
                int Total = 0;
                result.Data  = query.Pager <DTO.UserOPDRegisterDTO>(out Total, PageIndex, PageSize);
                result.Total = Total;
                return(result);
            }
        }
コード例 #8
0
        /// <summary>
        /// 通过主键判断记录是否存在(不含已删除)

        /// 日期:2016年7月29日
        /// </summary>
        /// <param name="ID">主键</param>
        /// <returns></returns>
        public virtual bool Exists(string ID)
        {
            if (_PK.Count <= 0)
            {
                throw new Exception("没有设置主键");
            }

            if (_PK.Count > 1)
            {
                throw new Exception("不支持复合主键");
            }

            using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities())
            {
                IQueryable <TEntity> cities = db.Set <TEntity>();
                ParameterExpression  param  = Expression.Parameter(typeof(TEntity), "TEntity");
                Expression           left   = Expression.Property(param, typeof(TEntity).GetProperty(_PK[0]));
                Expression           right  = Expression.Constant(ID);
                Expression           filter = Expression.Equal(left, right);
                return(db.Set <TEntity>().Where(Expression.Lambda <Func <TEntity, bool> >(filter, param)).Where(a => a.IsDeleted == false).Count() > 0 ? true : false);
            }
        }
コード例 #9
0
        /// <summary>
        /// 通过表达式获取一条记录(不含已删除)

        /// 日期:2016年7月29日
        /// </summary>
        /// <param name="where">查询条件</param>
        /// <returns></returns>
        public TEntity Single(Expression <Func <TEntity, bool> > where, List <Expression <Func <TEntity, object> > > includes = null)
        {
            using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities())
            {
                var query = db.Set <TEntity>().Where(where).Where(a => a.IsDeleted == false);

                if (includes != null)
                {
                    query = includes.Aggregate(query, (current, include) => current.Include(include));
                }

                var result = query.FirstOrDefault();


                return(result);
            }
        }