Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Varaible where clause in linq

Posted on 2014-02-26
1
Medium Priority
?
386 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 64

Accepted Solution

by:
Fernando Soto earned 2000 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

618 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