Ejemplo n.º 1
0
 /// <summary>
 /// 用==表示值被更改
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="obj"></param>
 /// <param name="expression"></param>
 public static void Change <T>(this T obj, Expression <Func <T, bool> > expression) where T : CRL.IModel, new()
 {
     if (expression.Body is BinaryExpression)
     {
         BinaryExpression be   = ((BinaryExpression)expression.Body);
         MemberExpression mExp = (MemberExpression)be.Left;
         string           name = mExp.Member.Name;
         var    right          = be.Right;
         object value;
         if (right is ConstantExpression)
         {
             ConstantExpression cExp = (ConstantExpression)right;
             value = cExp.Value;
         }
         else
         {
             value = LambdaCompileCache.GetExpressionCacheValue(right);
             //value = Expression.Lambda(right).Compile().DynamicInvoke();
         }
         obj.SetChanges(name, value);
     }
     else
     {
         obj.Change <T, bool>(expression);
     }
 }
Ejemplo n.º 2
0
 List <TModel> QueryFromCacheBase(Expression <Func <TModel, bool> > expression, out int total, int pageIndex = 0, int pageSize = 0)
 {
     total = 0;
     #region  KEY查找
     if (expression.Body is BinaryExpression)
     {
         var binary = expression.Body as BinaryExpression;
         if (binary.NodeType == ExpressionType.Equal)
         {
             if (binary.Left is MemberExpression)
             {
                 var member     = binary.Left as MemberExpression;
                 var primaryKey = TypeCache.GetTable(typeof(TModel)).PrimaryKey.Name;
                 if (member.Member.Name.ToUpper() == primaryKey.ToUpper())
                 {
                     var value = (int)LambdaCompileCache.GetExpressionCacheValue(binary.Right);
                     //var value = (int)Expression.Lambda(binary.Right).Compile().DynamicInvoke();
                     var all = GetCache(CacheQuery());
                     if (all == null)
                     {
                         return(new List <TModel>());
                     }
                     if (all.ContainsKey(value))
                     {
                         total = 1;
                         return(new List <TModel>()
                         {
                             all[value]
                         });
                     }
                     return(new List <TModel>());
                 }
             }
         }
     }
     #endregion
     var predicate = expression.Compile();
     var data      = AllCache.Where(predicate);
     total = data.Count();
     if (pageIndex > 0)
     {
         var data2 = Base.CutList(data, pageIndex, pageSize);
         return(data2);
     }
     return(data.ToList());
 }