locked
IQueryable or IEnumerable in Repository? RRS feed

  • Question

  • Hello,

    On an MVC application I have the following flow:

    Article Repository > GetAll() returns an IQueryable of Article

    Article Controller > Calls ArticleRepository.GetAll(), Apply PagedList to it, Maps IPagedList<Article> to IPagedList<ArticleItemViewModel>

    The questions:

       Should I return IEnumerable from the repository instead of IQueryable?

       Should I return IPagedList from the repository instead of IQueryable?

    I am doing the way I am doing because IQueryable let me apply queries in the controller if necessary ...

    ... But at the other hand the Repository should be closed and return the data with no more need of queries so IEnumerable would be enough and in the repository to have something like:

    GetAll(), GetAllPublished(), etc.

    But if the repository should return everything I need why not returning IPagedList and have GetAll(int index, int count) , ...?

    ... Well, because I see PagedList more as a presentation action. So having it on the controller before the mapping it makes sense so the mapping isn't applied to unnecessary aritcles.

    Anyway, what is your advice?

    I am just trying to find the best way to work with this.

    Thanks,

    Miguel
    Wednesday, September 16, 2009 9:32 PM

All replies

  • I am against returning generic interfaces in general. I would use a bindable collection for data change notification.
    Linq is not supported in older versions of compilers.


    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
    Friday, September 18, 2009 1:04 PM