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

后端 未结 5 1626
时光取名叫无心
时光取名叫无心 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 05:50

    I ended up creating two sets of methods, ones that return IEnumerable (in your case IQueryable), and ones that return Collection (pull the content before sending it out of the repository.)

    This allows me to do both build ad hoc queries in Services outside the repository as well as use Repository methods directly returning side effect resistant Collections. In other words, joining two Repository Entities together results in one select query, instead of one select query for each entity found.

    I imagine you could set your protection level to keep truly bad things from happening.

提交回复
热议问题