简体   繁体   中英

C# MVC Dynamic Linq OR Query

I am looking to build this query and am able to do it for 'AND' phrases, but not for 'OR' phrases based off of the format in the link below. The dynamic OR query will be combined with the 'AND' queries.

http://www.codeproject.com/Articles/168981/Guide-to-Creating-Dynamic-LINQ-Queries

Out of the box, creating a nested dynamic OR query isn't easily obtainable. You're probably looking for something like Predicate Builder or Dynamic Linq which will allow you to have the control over how things are converted to SQL.

I ended up using the method in the original link posted with sql queries integrated.

http://www.codeproject.com/Articles/168981/Guide-to-Creating-Dynamic-LINQ-Queries

What exactly are you trying to query? Do you have any code snippets. From the example you could try modifying this snippet

oDataQuery = oDataQuery.Where(a => a.CustomerID == CustomerID);

to be

oDataQuery = oDataQuery.Where(a => (a.CustomerID == CustomerID) || (a.Something == Something));

Reference this stack overflow question

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM