0

I read Repositories should NOT utilize IQueryable. Simple repository example have ListAll, FindById, Add, Delete. Below is a sample Product Repository ListAll. If I cannot overlay queries, and require searching queries eg, ProductTable by Category, or ProductTable by Weight (intricate queries), I will then require a DAO (Data Access Object Pattern).

So question is,

(a) is it okay to have a Repository Pattern and DAO Pattern in same application?

(b) Doesn't this bypass the whole point of having a DDD Repository Pattern?

How would I access ProductTable having Intriciate requests while still going through repository? The first Repository query will be slow.

public virtual IEnumerable<Products> List()
{
    return _dbContext.Products.AsEnumerable();
}

// This repository pattern will be slow, first it access all product and Then filters

var result = context.products()
               .Where(o => o.ProductCategoryId== 5);


// This is dao pattern, with more specific queries

var result = context.products.AsEnumerable()
               .Where(o => o.ProductCategoryId== 5);

Entity Framework Repository Pattern why not return Iqueryable?

https://deviq.com/repository-pattern/

  • you can use specification approach as used [here](https://github.com/dotnet-architecture/eShopOnWeb/tree/master/src/ApplicationCore/Specifications) – Mujahid Daud Khan Oct 02 '18 at 09:52

1 Answers1

0

A repository is geared towards an aggregate. It returns a fully constituted aggregate that you use mainly for transactional purposes. Changes to your data are effected through the aggregates. You should not really be querying aggregates as they may not be the best at returning the relevant/concise data.

A query layer is a read model that returns only the relevant data in as lightweight a mechanism as possible. You may view this as a DAO but it isn't really the same thing although it most certainly is focused on data retrieval.

In that sense what you are proposing i.t.o. the two mechanisms isn't only viable but I would strongly recommend you go that route :)

Since the intention between the two mechanisms is so divergent having a query mechanism in no way diminishes the usefulness of a repository.

Eben Roux
  • 12,983
  • 2
  • 27
  • 48