从EF </t>生成动态IQueryable <t>

时间:2011-11-22 15:21:42

标签: entity-framework iqueryable

我有一张满是订单的表,其中每个订单都有一个州(例如:failed, denied, pending, cancelled or success

如何编写动态查询以按状态返回订单,我将传递一个或多个状态?

即所有失败,拒绝或取消的订单:

IQueryable<MyType> query = from o in Model.Orders
                           where o.OrderStatus == ("Failed" || "Denied" || "Cancelled")
                           select o;

1 个答案:

答案 0 :(得分:4)

您可以尝试使用Contains方法

string[] status = {"Failed", "Denied", "Cancelled"};

IQueryable<MyType> query = from o in Model.Orders
                           where status.Contains(o.OrderStatus)
                           select o;