How can I write a clean Repository without exposing IQueryable to the rest of my application?

后端 未结 5 1623
时光取名叫无心
时光取名叫无心 2021-01-31 05:26

So, I\'ve read all the Q&A\'s here on SO regarding the subject of whether or not to expose IQueryable to the rest of your project or not (see here, and here), and I\'ve ulti

5条回答
  •  孤街浪徒
    2021-01-31 06:00

    Rob's method really doesn't solve your core problem, and that is not wanting to write individual methods for each type of query you'd like to run, and unfortunately if you're not using IQueryable then that is what you are left with.

    Sure the methods might be in the "service" layer, but it still means having to write "GetProductsByName, GetProductsByDate"...

    The other method is something like:

    GetProducts(QueryObject);
    

    This might give you some benefit over using IQueryable in that you can constrain what is returned.

提交回复
热议问题