Disclaimer : I could not find all the answers from another question on SO.
While preparing a query in LINQPad I observed that some results were returned as IQueryable where as some in DbSet.
All the versions of the query can be found here : https://dotnetfiddle.net/r1ghBv
// returns IQueryable<Message>
// Time : 133 ms
from m in Messages
where m.MessageStatusId < 5 && (
from mm in Messages
where mm.MessageStatusId < 5
group mm by mm.F_Id into g
select g.Key
).Contains(m.F_Id)
select m
vs
// returns DbQuery<Message>
// Time : 112 ms
from mm in Messages
where mm.MessageStatusId < 5
group mm by mm.F_Id into g
from m in g
select m
In LINQPad, DbQuery version had 89 lines of IL where as for IQueryable it was 171.
DbQuery is a class vs IQueryable is an interface, and DbQuery clearly seem to have more methods. But I am interested to know which might have better SQL performance if I was to use following queries in C# .NET 4.5.2 and Entity Framework 6.x ?
Questions :
- How does the return type got decided in queries above ?
- The DbQuery version had 7 extra SQL Queries in LINQPad's SQL tab before the actual query where as in IQueryable version LINQPad simply generated the query straight up even-though why DbQuery was a little faster ? Is that because DbQuery, an EF Library class ?