2015-11-10 3 views
-1
PropertyInfo[] All_prop = Get_All_prop2(Model); 
    //------Get Properties has Value----- 
    foreach (PropertyInfo property in All_prop) 
    { 
     //--Check Has Value Property 
     if (property.GetValue(this, null) != null) 
     { 
      IQueryable<DAL_BankWebApp.TBUSER> Query = cntx.TBUSERs.Select(x => x); 
      //--Create Expression Of Property 
      ParameterExpression pe = Expression.Parameter(typeof(string), property.Name); 

      ConstantExpression Constant = Expression.Constant(property.GetConstantValue()); 
      Expression Contain = Expression.Call(pe, typeof(string).GetMethod("Contains", new[] { typeof(string) }), Constant); 
      //----Create Where 
      MethodCallExpression whereCallExpression = Expression.Call(
       typeof(Queryable), 
       "Where", 
       new Type[] { Query.ElementType }, 
       Query.Expression, 
       Expression.Lambda<Func<string, bool>>(Contain, new ParameterExpression[] { pe })); 

      IQueryable<DAL_BankWebApp.TBUSER> results = Query.Provider.CreateQuery<DAL_BankWebApp.TBUSER>(whereCallExpression); 
      Result = results; 
     } 
    } 

я получаю ниже ошибки В => если (property.GetValue (это, нуль)! = NULL)Ошибка создания динамических Linq запросов Expression

база { "Объект не соответствует целевой тип. «} {System.ApplicationException System.Reflection.TargetException}

ответ

0

я Решено: если (property.GetValue (модель, нуль)! = NULL)

Смежные вопросы