如何在LINQ to Entity中应用动态过滤 [英] How to apply dynamic filtering in LINQ to Entity
问题描述
您好
我使用的是.net 4.5。我们使用jQGrid在UI和MVC上显示数据。目前我们要求进行分页,排序和搜索。我们正在为搜索功能创建通用组件。这样我们就可以将组件
应用于其他网格。
I am using .net 4.5. We are using jQGrid for displaying data on UI and MVC. Currently we have requirement to have paging,sorting and searching. We are in the process of creating generic component for Search functionality. so that we apply that a component to other grids.
我正面临过滤问题。我不知道运行时的列。那么在这种情况下如何应用过滤。我知道如果我知道编译时的列名,我可以应用过滤器。在我的情况下,在编译时不知道columnname如何
为此写入过滤查询。
I am facing an issue with Filtering. I don't know the column at runtime. So How can apply filtering in this case. I know i can apply the filter if i know the columnname at the time of compiletime. In my case columnname is not known at compile time how to write filtering query for this.
Dhanaji
推荐答案
嗨Dhanaji,
Hi Dhanaji,
如果您有权访问该实体,您可以在linq中将其过滤为实体。
If you have access the entity, you could filter it in linq to entity.
例如。
using (AdventureWorksEntities context = new AdventureWorksEntities())
{
var onlineOrders =
from order in context.SalesOrderHeaders
where order.OnlineOrderFlag == true
select new
{
SalesOrderID = order.SalesOrderID,
OrderDate = order.OrderDate,
SalesOrderNumber = order.SalesOrderNumber
};
foreach (var onlineOrder in onlineOrders)
{
Console.WriteLine("Order ID: {0} Order date: {1:d} Order number: {2}",
onlineOrder.SalesOrderID,
onlineOrder.OrderDate,
onlineOrder.SalesOrderNumber);
}
}
最好的问候,
Youjun Tang
Best regards,
Youjun Tang
这篇关于如何在LINQ to Entity中应用动态过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!