本文介绍了LINQ中的动态连接0 C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var query = from C in db.clients
join O in db.orders on c.clientid equals O.clientid
join P in db.products on O.productid equals P.productid
select new {C,O};
我想基于上述联接进行搜索.输入参数可以是
I want to perform a search based on the above join. The input param could be
C.ClientID和/或P.ProductName和/或P.ProductType和/或O.ShippingType
C.ClientID and/or P.ProductName and/or P.ProductType and/or O.ShippingType
我将如何构建动态搜索子句?
How would i build a dynamic search clause?
推荐答案
另一种方法:
Expression<Func<Client, bool>> clientWhere = c => true;
Expression<Func<Order, bool>> orderWhere = o => true;
Expression<Func<Product, bool>> productWhere = p => true;
if (filterByClient)
{
clientWhere = c => c.ClientID == searchForClientID;
}
if (filterByProductName)
{
productName = p => p.ProductName == searchForProductNameString;
}
// other filter cases
var query = from C in db.clients.Where(clientWhere)
join O in db.orders.Where(orderWhere) on c.clientid equals O.clientid
join P in db.products.Where(productWhere) on O.productid equals P.productid
select new {C,O};
这篇关于LINQ中的动态连接0 C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!