简体   繁体   English

n带有实体框架的分层Asp.net应用

[英]n Layered Asp.net app with Entity framework

I am facing the same issue as the one below 我面临与以下问题相同的问题

Entity Framework 6 and Unit Of Work… Where, When? 实体框架6和工作单元…在哪里,何时? Is it like transactions in ado.net? 就像ado.net中的交易一样吗?

As per the answer, i shouldn't create an abstraction layer over EF, but i want to keep my business layer independent. 按照答案,我不应该在EF之上创建抽象层,但我想保持业务层独立。 So i decided to go with the last option, adding TransactionScope. 因此,我决定采用最后一个选项,即添加TransactionScope。 But i read, that it affects the performance. 但是我读到,它会影响性能。 I have kept the IsolationLevel to ReadCommitted. 我将IsolationLevel保留为ReadCommitted。 But i am not sure about the performance. 但是我不确定性能。

So how can i use EF without adding its dependency to business layer. 因此,如何在不将EF依赖性添加到业务层的情况下使用EF。

My business objects are different from Entity objects. 我的业务对象与实体对象不同。

If you don't want to draw a dependency on EF, you're going to have to abstract it out. 如果您不想依赖EF,则必须将其抽象出来。 The poster in the response you mentioned believes this is too much code, but if you want to decouple the data layer implementation from the business layer it's a necessary evil. 您提到的响应中的发布者认为这是太多的代码,但是如果您想将数据层实现与业务层分离,这是必不可少的。

Historically I've gone with a relatively generic IRepository implementation that's generated from an IUnitOfWork such as: 从历史上看,我使用了从IUnitOfWork生成的相对通用的IRepository实现,例如:

uow.Get<IRepositoryType>()

By using an IoC container (using TinyIoC lately) we're able to handle and swap out our implementations easily, and keep our domain object separate from our data objects. 通过使用IoC容器(最近使用TinyIoC),我们可以轻松地处理和交换我们的实现,并使域对象与数据对象分离。

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

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