简体   繁体   English

具有实体框架6的实用程序DAL层

[英]Utility DAL layer with entity framework 6

I'm wondering about the utility of making a dal layer with EF. 我想知道用EF制作dal层的实用性。 Why not calling EF directly in business layer, considering EF DBContext is a unitOfWork and List DBSet are repositories ? 考虑到EF DBContext是unitOfWork并且List DBSet是存储库,为什么不直接在业务层中调用EF呢? So why adding an extra DAL layer, wich is finally a facade.. The only advantage i see, is in case of we have to change the data access implementation, like replace EF by Hibernate or other. 因此,为什么要添加一个额外的DAL层,最终还是要成为一个外观。.我看到的唯一优势是,如果我们不得不更改数据访问实现,例如用Hibernate或其他方法替换EF。 But honestly, i've never seen that happen. 但老实说,我从未见过这种情况。

Actually with a data mapper the necessity of developing a DAL is plain useless because it would contain 0 lines of code. 实际上,对于数据映射器,开发DAL的必要性毫无用处,因为它包含0行代码。

Everything on top of a data mapper isn't a data access layer but actual domain, because a data mapper implementation like an OR/M translates your objects into the underlying relational data and viceversa, and you work on top of them is to develop your domain and miss the pain of object-relational impedance. 数据映射器之上的所有内容都不是数据访问层,而是实际域,因为像OR / M这样的数据映射器实现将您的对象转换为基础关系数据,反之亦然,而您在它们之上进行的工作就是开发您的并错过了对象关系阻抗的痛苦。

The point of introducing the repository pattern on top of a data mapper is because you want to both be able to switch the underlying data store even to a non-relational one in the long run (also, switch from NoSQL to SQL, who knows!), and there's another definitive reason to introduce the repository layer in your software: because you want to be able to mock the data store with fakes in order to unit test your domain . 在数据映射器之上引入存储库模式的意义在于,从长远来看,您希望两者都能够将基础数据存储甚至切换到非关系存储(也要从NoSQL切换到SQL,谁知道! ),并且在软件中引入存储库层还有另一个明确的理由: 因为您希望能够使用伪造品来模拟数据存储,以便对您的域进行单元测试

Finally, even when Entity Framework implements unit of work and other patterns, sometimes their implementation may not suit your own domain requirements and you need to wrap them to provide more concretion to your domain. 最后,即使Entity Framework实现了工作单元和其他模式,有时它们的实现也可能不适合您自己的域要求,因此您需要包装它们以为您的域提供更多内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM