Пример #1
0
 //add by iLine 20160427 增加条件查询
 /// <summary>
 /// 根据条件获取数据
 /// </summary>
 /// <typeparam name="TEntity"></typeparam>
 /// <param name="predicate"></param>
 /// <param name="isTracking"></param>
 /// <returns></returns>
 public virtual IList <TEntity> GetDatas <TEntity>(Expression <Func <TEntity, bool> > predicate) where TEntity : EntityBase
 {
     using (iCMSDbContext ctx = new iCMSDbContext())
     {
         if (predicate != null)
         {
             return(ctx.Set <TEntity>().Where(predicate).ToList());
         }
         else
         {
             return(null);
         }
     }
 }
Пример #2
0
        /// <summary>
        ///  更新
        /// </summary>
        /// <typeparam name="TEntity"> 要注册的类型 </typeparam>
        /// <param name="entity"> 要注册的对象 </param>
        public virtual OperationResult Update <TEntity>(TEntity entity) where TEntity : EntityBase
        {
            string exMsg = string.Empty;

            try
            {
                using (iCMSDbContext ctx = new iCMSDbContext())
                {
                    if (ctx.Entry(entity).State == EntityState.Detached)
                    {
                        ctx.Set <TEntity>().Attach(entity);
                    }

                    ctx.Entry(entity).State = EntityState.Modified;
                    ctx.SaveChanges();

                    //try
                    //{
                    //    #region 云推送添加
                    //    BaseCloudService cloud = BaseCloudService.GetInstance();
                    //    cloud.SyncInfo(entity, EnumCloudDataOperation.Update);
                    //    #endregion
                    //}
                    //catch (Exception ex)
                    //{
                    //    LogHelper.WriteLog(ex);
                    //}
                    //finally
                    //{

                    //}

                    #region 云平台修改 Multi Thread

                    //Thread thread = new Thread(YunyiThreadHelper.YunyiUpdate);
                    //thread.Start(entity);

                    #endregion

                    return(new OperationResult(EnumOperationResultType.Success, "操作成功!"));
                }
            }
            catch (Exception ex)
            {
                exMsg = ex.Message;

                LogHelper.WriteLog("数据库操作错误:" + ex.Message);
            }
            return(new OperationResult(EnumOperationResultType.Error, exMsg));
        }
Пример #3
0
 private IQueryable <TEntity> Set <TEntity>(iCMSDbContext ctx, Expression <Func <TEntity, bool> > predicate) where TEntity : EntityBase
 {
     return(ctx.Set <TEntity>().Where(predicate).AsQueryable());
 }
Пример #4
0
 /// <summary>
 ///   为指定的类型返回 System.Data.Entity.DbSet,这将允许对上下文中的给定实体执行 CRUD 操作。
 /// </summary>
 /// <typeparam name="TEntity"> 应为其返回一个集的实体类型。 </typeparam>
 /// <returns> 给定实体类型的 System.Data.Entity.DbSet 实例。 </returns>
 private DbSet <TEntity> Set <TEntity>(iCMSDbContext ctx) where TEntity : EntityBase
 {
     return(ctx.Set <TEntity>());
 }