Repository pattern with EF4 CTP5

前端 未结 2 764
梦如初夏
梦如初夏 2021-02-06 13:43

I\'m trying to implement the repository pattern with ef4 ctp5, I came up with something but I\'m no expert in ef so I want to know if what I did is good.

<
2条回答
  •  野的像风
    2021-02-06 13:46

    I may get voted down for this, but DbContext already is a repository. When you expose your domain models as collection properties of your concrete DbContext, then EF CTP5 creates a repository for you. It presents a collection like interface for access to domain models whilst allowing you to pass queries (as linq, or spec objects) for filtering of results.

    If you need an interface, CTP5 doesn't provide one for you. I've wrapped my own around the DBContext and simply exposed the publicly available members from the object. It's an adapter for testability and DI.

    I'll comment for clarification if what I said isn't apparently obvious.

提交回复
热议问题