我正在编写一个动态linq查询来实现分页,现在我遇到一个问题,我需要该System.Linq.Expressions.Expression.Like
功能,但它不存在System.Linq.Expressions.Expression
,这是我的代码。
Expression mWhereFunc; // Filter clause
ParameterExpression mLinqParam; // Linq param
// Get current request page
string mCurPage = this.Request.QueryString["page"];
if (String.IsNullOrEmpty(mCurPage))
{
mCurPage = "1";
}
mLinqParam = Expression.Parameter(typeof(ORD_Order), "p");
mWhereFunc = Expression.Equal(Expression.Property(mLinqParam,
typeof(ORD_Order).GetProperty("ItemIsValid")),
Expression.Constant(true));
string mOrderSN = this.Request.QueryString["txtOrderSN"];
if (!String.IsNullOrEmpty(mOrderSN))
{
mWhereFunc = Expression.And(mWhereFunc,
**Expression.Equal**(Expression.Property(mLinqParam,
typeof(ORD_Order).GetProperty("OrderSN")),
Expression.Constant(mOrderSN)));
}
var mLambdaWhere = (Expression<Func<ORD_Order,
bool>>)Expression.Lambda<Func<ORD_Order, bool>>(mWhereFunc,
new ParameterExpression[] { mLinqParam });
Func<ORD_Order, Int32> mLambdaOrder = p => p.OrderID;
IORD_OrderRepository rptOrder = new ORD_OrderRepository();
ICTM_CustomerRepository rptCtm = new CTM_CustomerRepository();
var list = from o in rptOrder.GetAll()
.Where(mLambdaWhere)
.OrderBy(mLambdaOrder)
.Skip((int.Parse(mCurPage) - 1) * mPageSize).Take(mPageSize)
join c in rptCtm.GetAll()
on o.CustomerID equals c.CustomerID
select new
{
o.OrderID,
o.OrderSN,
o.CustomerID,
c.ContactName,
o.Status,
o.CreateDate,
o.Description
};
Expression.Equal是我想将其更改为 Expression.Like 的地方
任何帮助将不胜感激。