views:

241

answers:

1

Hi there,

i have been reading when using Linq to entites a query is of type IQueryable before it is processed but when the query has been processed, it's no longer an IQueryable, but an ObjectQuery.

In that case, is it correct to write methods from my layer (repository layer) to return IQueryable?

Do i need to cast?

Why would i want to return an objectQuery?

Sorry coming form a LINQ to SQL background where things were always IQueryable but EF seems to have changed this

Any help really appreciated

Thanks in advance

+1  A: 

My repositories always returns IQueryable. The reason for this is that IQueryable is not dependent on EF whereas ObjectQuery is. So if I want my other layers to be persistance ignorant I don't want to introduce dependency on ObjectQuery.

ObjectQuery is implementation of IQueryable with several additional features. First feature you will quickly discover is Include function which is need for eager loading of navigation properties (related entities). Second feature is EQL - entity query language. EQL is second way how you can query your conceptual model. It has similar syntax as SQL. You can write simple query as string, pass it to ObjectQuery constructor and execute query or use it in Linq-To-Entities.

Ladislav Mrnka
thank you.. ok iqueryable it is then :-) ... i don't think i need any of the advance features of objectquery... ermmm do i need to cast .. as from a linq to entities query it is an objectquery that is returned... so when i return the object from my method.. do i need to cast or something? Thanks again
mark smith
No you don't need to cast.
Ladislav Mrnka
Thanks great! just what i needed!
mark smith