有时候我们需要在XAF中使用Linq表达式,同时可能还需要使用XAF的CriteriaOperator,那么除了System.Linq还需要用到这四个个命名空间中的内容
using DevExpress.Xpo;
using DevExpress.Data.Filtering;
using DevExpress.Data.Linq;
using DevExpress.Data.Linq.Helpers;
下面是使用Linq和CriteriaOperator作为附加过滤条件的例子:
XPQuery<Customer> _customer = new XPQuery<Customer>(((XPObjectSpace)ObjectSpace).Session);
var query = from c in _customer
where c.Id > 10
select c;
CriteriaToExpressionConverter converter = new CriteriaToExpressionConverter();
BinaryOperator bo = new BinaryOperator("Text", "s%",BinaryOperatorType.Like);
IQueryable<Customer> filteredData = query.AppendWhere(converter, bo) as IQueryable<Customer>;
foreach (var i in filteredData)
Console.WriteLine(i.Id + " " + i.Text);