Repository Pattern without an ORM

后端 未结 3 1314
清酒与你
清酒与你 2021-02-05 05:46

I am using repository pattern in a .NET C# application that does not use an ORM. However the issue I am having is how to fill One-to-many List properties of an entity. e.g. if a

3条回答
  •  半阙折子戏
    2021-02-05 06:14

    1) Should I load the Orders list within the GetCustomerById method?

    It's probably a good idea to separate the order mapping code from the customer mapping code. If you're writing your data access code by hand, calling that mapping module from the GetCustomerById method is your best option.

    2) What if the Order itself has another list property and so on?

    The logic to put all those together has to live somewhere; the related aggregate repository is as good a place as any.

    3) What if I want to do lazy loading? Where would I put the code to load the Orders property in customer? Inside the Orders property get{} accessor? But then I would have to inject repository into the domain entity? which I don't think is the right solution.

    The best solution I've seen is to make your repository return subclassed domain entities (using something like Castle DynamicProxy) - that lets you maintain persistence ignorance in your domain model.

提交回复
热议问题