IEnumerable ...

S

shapper

Hello,

I am working on a few repositories ...

I think when using repositories an IEnumerable should be returned
instead of IQueryable or IList, correct?

As far as I know, when using repositories, all the queries should be
placed inside the repositories methods and return only the
IEnumerable ...

Probably in terms of performance is also better.

Am I wrong?

Thanks,
Miguel
 
A

Arne Vajhøj

I am working on a few repositories ...

I think when using repositories an IEnumerable should be returned
instead of IQueryable or IList, correct?

As far as I know, when using repositories, all the queries should be
placed inside the repositories methods and return only the
IEnumerable ...

Probably in terms of performance is also better.

Am I wrong?

It is not clear to me what type of repositories you are
talking about, so I can not comment on the substance.

But I will note that:
- IQueryable extends IEnumerable
- you will always return an instance of a concrete class
even though the method is declared to return an interface

Arne
 
S

shapper

It is not clear to me what type of repositories you are
talking about, so I can not comment on the substance.

Basically the repositories query a SQL database using Linq to SQL or
Linq to Entities and return one or more entities.
Some methods are FindById, FindAll, FindByCity, etc
I am not sure if this is what you were asking.
But I will note that:
- IQueryable extends IEnumerable
Yes, I know but that is why I say IEnumerable should be used.
Why having a repository to return a list and then query that list
again?
Afer using a Repository method, like FindByCity, I think the logic is
to display the data not to query it again before displaying it.
It makes more sense to create a new method in the repository if needed
for extra functionality.

Not?

Thanks,
Miguel
 
A

Arne Vajhøj

Basically the repositories query a SQL database using Linq to SQL or
Linq to Entities and return one or more entities.
Some methods are FindById, FindAll, FindByCity, etc
I am not sure if this is what you were asking.

Yes, I know but that is why I say IEnumerable should be used.
Why having a repository to return a list and then query that list
again?
Afer using a Repository method, like FindByCity, I think the logic is
to display the data not to query it again before displaying it.
It makes more sense to create a new method in the repository if needed
for extra functionality.

Not?

IList also extends IEnumerable.

So if you return an IList then you will have all the
functionality of IEnumerable plus some extra functionality.

So I do not understand your argument.

Arne
 
H

Harlan Messinger

shapper said:
Basically the repositories query a SQL database using Linq to SQL or
Linq to Entities and return one or more entities.
Some methods are FindById, FindAll, FindByCity, etc
I am not sure if this is what you were asking.

Yes, I know but that is why I say IEnumerable should be used.

It *is* IEnumerable--by virtue of being IQueryable.
Why having a repository to return a list and then query that list
again?

You don't have to query anything again. You have an object of a type
that implements IEnumerable, exactly as you say you would like. Since it
also implements IQueryable, you *could* query it to obtain a subset of
it if your application called for you to do so, but this is not an
obligation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top