Entity framework 6 providing repositories and UoW out of the box

后端 未结 2 1218
旧巷少年郎
旧巷少年郎 2021-01-01 00:30

But how do you use it?

I have a Code First project set up, and trying out some stuff with this new EF6. Reading all kinds of posts/blogs from at least 2

2条回答
  •  被撕碎了的回忆
    2021-01-01 01:14

    Entity Framework in itself can be considered a Repository. It facilitates work with data, in this case a database. This is all that a Repository does.

    If you want to build another Repository on top of what EF provides, it is completely up to you - or to your business rules.

    Many complex projects uses 2-3 layers of repositories with web services between. The performance is lower but you gain on other plans like security, resilience, separation of concerts, etc.

    Your company might decide that it's in their best interest to never access data directly from front-end projects. They might force you to build a separate web-service project, which will be accessible only from localhost. So you will end up having EF as Repository in the webservice project. On the front-end side you will obviously need to build another Repository which will work with the web-service.

    It also depends a lot of your project. If it's a small project it really it's overkill to build a second Repository on top of EF. But then again, read above. Nowadays security matters a lot more than performance.

    To be politically correct I'm including the comment made by Wiktor Zychla:
    "DbSet is a repository and DbContext is a Unit of Work. "Entity Framework is a Repository" could lead to unnecessary confusion."

提交回复
热议问题