1

Is there a way to define a dbset (or other iqueryable type) as a query string?

Example:

var myQuery = "Select * from dbo.MyTable";

var dbset = context.Set<MyTableRow>(myQuery); //Hypothetical Overload

So I could then go with something like

dbset.Where(x => x.SomeProperty == 1);

I am trying to dynamically set a dbset from a dynamic sql string.

Ezra Bailey
  • 1,434
  • 13
  • 25
  • 1
    You are going to want to avoid directly using a string to form a query. As long as there is a lambda conversion it should be okay, but be careful about using strings which contain user input in their raw form. – Travis J Aug 11 '14 at 20:56
  • 1
    You should look into ESql: http://stackoverflow.com/questions/38647/performance-of-linq-to-entities-vs-esql – Jens Kloster Aug 11 '14 at 20:56
  • @TravisJ Thanks for the mention! The string will be safe! – Ezra Bailey Aug 11 '14 at 20:58

0 Answers0