2009-08-11 7 views
0
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}; 

Je souhaite effectuer une recherche basée sur la jointure ci-dessus. L'entrée param pourrait êtrejointure dynamique dans linq 0 C#

C.ClientID et/ou P.ProductName et/ou P.ProductType et/ou O.ShippingType

Comment puis-je construire une clause de recherche dynamique?

Répondre

0

Une autre méthode:

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}; 
Questions connexes