Solved

Using variable in Linq query

Posted on 2011-02-16
1
604 Views
Last Modified: 2013-11-11
I'm trying to do something like this in Linq To Entities:
string criteria = FuncToCalcCriteria();
“Select * from tablename where SomeField “  + criteria;//could be >< <>= etc.etec.
? I'm getting 'Method cannot be translated into a store expression' if I put the method into the Linq, but I can't concatenate expressions like you do in SQL strings, so is there a way round?
0
Comment
Question by:Silas2
1 Comment
 
LVL 21

Accepted Solution

by:
naspinski earned 250 total points
ID: 34906466
The Dynamic LINQ library has you covered:

http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

Scott Guthrie explains it better than I ever could.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

840 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