Suppose there is a database and the interaction with it is performed through some kind of ORM.

Actually, the question is how to properly hide it from the outside world, but not to the detriment of usability and so that at any moment it can be easily changed to another?

I see a solution in the form of some kind of service in which some method is twitching and it returns some kind of result. However, the problem with this approach is that many methods of the GetBy* type can ultimately come up, although if you work directly with ORM, you can filter everything on the fly in LINQ style without creating an add. methods.

Another solution is to expose Enumerable , but in that case, if I am not mistaken, the data will completely materialize, which is not good, but there will be flexibility comparable to direct interaction through ORM ...

  • You can hide any architectural layer by creating a set of Dto on the border and that's it, no one knows about classes abroad. Only for any layer you need to pay ( tynts ). Are you ready to pay for abstraction from ORM by creating all classes in duplicate? And, it is not entirely clear why you think that you can avoid materialization of data: did you so vaguely describe the question (service between applications? Between application layers?) That you can say "in fact, sooner or later you will have to materialize data." - AK
  • By materialization in the second example, I mean the property => context.Entity.Select (x => x). Ie the whole essence of materialize. - iluxa1810
  • And where do you put it? In your own application in another layer or "out" in the "outside world", in the WCF / WebApi service, which are you talking about in the last questions? - AK
  • To another layer .. - iluxa1810
  • Then I agree that this is a holivarny question and very dependent on tasks - and we already talked about it, we talked about it on the browser, and IEnumerable happens well and IQuerable. Let's minus this part of the question, so as not to go away in the favorite colors of felt-tip pens (I personally think that IEnumerable needs to be written - and if I suddenly want to "oh, but it would be good to filter here again" - then I immediately go to review the original request) - AK

0