Using SqlQuery to get IQueryable

entity-framework entity-framework-6

Question

Is there anything that can bring it back?IQueryable for an Entity Framework 6 dynamic SQL query?

I now use this, however it pulls all the records (as expected).

DbContext.Database.SqlQuery<T>("SELECT * FROM dbo.SomeDynamicView")

The issue is thatSqlQuery yields the value DbRawSqlQuery.IEnumerable .

dbo.SomeDynamicView is a run-time-generated database view.

1
17
10/1/2014 3:29:39 PM

Accepted Answer

You cannot obtain aIQueryable from SqlQuery This is because of what, *IQueryable is doing is dynamically creating a SQL string based on the select and location filters you enter. since inSqlQuery Your contribution is the string That dynamic string cannot be produced by Entity Framework.

You can either create the string dynamically yourself to send toSqlQuery utilize it as aIEnumerable in place ofIQueryable or employDbSet in theDbContext and follow the more "conventional" route of allowing entity framework to construct the query for you.


* Technically, you can by calling AsQueryable() on the result, but it only gives you the benefits of using a "Actual" IQueryable, such as only fetching the necessary data from the server.

19
11/23/2015 3:52:18 AM

Popular Answer

ZZZ_tmp


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow