Solved

Varaible where clause in linq

Posted on 2014-02-26
1
377 Views
Last Modified: 2016-02-10
I have a generic List T, I need to query this list based on which field in this list is selected , so I need to have a variable where clause, how can I achieve this

List<T>, has GroupCode, Product, Country, Region

Currently I am doing

if (field =  GroupCode)
newfilteredList = (from p in filteredList.Where(r => r.GroupCode == FilterValue)

else if field =  product)
newfilteredList = (from p in filteredList.Where(r => r.product == FilterValue)


I want to do something like
newfilteredList = (from p in filteredList.Where(WhereClause)

Where the WhereClause would be some string witht he FilterField and value
0
Comment
Question by:countrymeister
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39889986
Seeming that Linq is a strongly typed extension using strings in where clause in that way is not supported directly. You can use, "Dynamic LINQ (Part 1: Using the LINQ Dynamic Query Library)", too accomplish this. At this link you will find samples on how to use it and where to download the library.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question