Solved

Using variable in Linq query

Posted on 2011-02-16
1
605 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…

685 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