本文介绍了实体框架VS纯Ado.Net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

EF是一种用途非常广泛的员工,但我不知道该如何使用它。在使用不同方法的不同项目中,EF遇到了很多问题。所以有些问题浮现在我的脑海。答案使我使用带有存储过程的纯ado.net。

EF is so widely used staff but I don't realize how I should use it. I met a lot of issues with EF on different projects with different approaches. So some questions brought together in my head. And answers leads me to use pure ado.net with stored procedures.

所以问题是:


  1. 如何在n层应用程序中处理EF?

    例如,我们有一些带有EF的DAL。我看到很多文章和项目都使用存储库,工作单元模式作为EF的某种抽象。我认为这种方法会扼杀提高开发速度的大部分好处,并导致几件事:

  1. How to deal with EF in n-tier application?
    For example, we have some DAL with EF. I saw a lot of articles and projects that used repository, unit of work patterns as some kind of abstraction for EF. I think such approach kills most of benefits that increase development speed and leads to few things:


  • 重新映射EF负载会导致某些DTO破坏性能(请参见选择以获取表数据-第一个循环,第二个循环-将结果映射到ef生成的某种复合类型,其次-使用linq过滤映射的数据,最后将其映射到某个DTO。完全重新映射到DTO是最大的efs好处的杀手;


  • 导致EF之间的强大凝聚力(并且版本)和应用。它将类似于带有dal和bll演示文稿的2层应用程序或带有bll和演示文稿的dal演示程序。我认为这不是最佳做法。除了映射外,加载过程与之前的加载过程相同,因此再次引起了性能问题。我们可以尝试使用EF作为DAL,而无需在其下进行任何抽象。但是我们会通过其他方式得到类似的问题。

  • remapping of EF load results in some DTO that kills performance(call some select to get table data - first loop, second loop - map results to some composite type generated by ef, next - filter mapped data using linq and, at last, map it to some DTO). Exactly remapping to DTO is killer of one of the biggest efs benefit;
    or
  • leads to strong cohesion between EF (and it's version) and app. It will be something like 2-tier app with dal and presentation with bll or dal with bll and presentation. I guess it's not best practice. And the same loading process as we have for previous thing except mapping, so again performance issue raised up. We could try to use EF as DAL without any abstraction under them. But we will get similar issues in some other way.

我应该为每个应用使用一个上下文\线程\原子操作?使用方法-每个应用程序一个线程一个上下文可能会稍微提高性能和调用导航属性的可能性,但是我们遇到另一个问题-更新此上下文并在上下文中增长加载的数据,我也不确定每个应用程序使用一个dbcontext的并发性\线。每次操作使用上下文会导致我们将EF结果重新映射到DTO。因此,您看到我们再次回到问题1。

Should I use one context per app\thread\atomic operation? Using approach - one context per app\thread may slightly increase performance and possibilities to call navigation properties, but we meet another problem - updating this context and growing loaded data in context, also I'm not sure about concurrency with one dbcontext per app\thread. Using context per operation will lead us to remapping EF results to our DTO's. So you see that we again pushed back to question no.1.

我们可以仅尝试使用EF +存储过程吗?同样,我们遇到了先前问题的问题。如果不使用大部分功能,使用EF的原因是什么?

Could we try to use EF + stored procedures only? Again we have issues from previous questions. What is the reason to use EF if the biggest part of functionality will not be used?

因此,是的,EF是伟大的开始项目。

So, yes EF is great to start project. It so convenient when we have few screens and crud operations.

但是接下来要做什么?

所有这些文字只是未分类的想法。我知道纯ado.net会带来另一种挑战。

All this text is just unsorted thoughts. I know that pure ado.net will lead to another kind of challenges.

那么,您对此主题有何看法?

So, what is your opinion about this topic?

推荐答案

按照命名约定,您会发现它的名称为:ADO.NET Entity Framework,这意味着Entity Framework位于ADO.NET的顶部,因此它不能更快​​,它可能会在相同的时间执行这两个操作,但是让我们看一下EF提供的功能:

By following the naming conventions , you will find it's called : ADO.NET Entity Framework , which means that Entity Framework sits on top of ADO.NET so it can't be faster , It may perform both in equal time , but let's look at EF provides :


  • 您将不会再因编写查询而陷入困境,而不必担心

  • 它使您可以依靠C#或自己喜欢的.NET语言编写自己希望从目标用户接受的数据约束。直接在模型类中。

最后:EF和LINQ为以后的应用程序维护提供了强大的功能。

Finally : EF and LINQ give a lot of power in maintaining your applications later .

使用Entity Framework可以使用三种不同的模型:模型优先,数据库优先和代码优先了解em。

There are three different models with the Entity Framework : Model First , Database First and Code First get to know each of 'em .

-在进行重新映射时会降低性能的要点,这是因为在第一次运行时,EF将元数据加载到内存中,并且在构建内存时需要花费时间edmx文件中模型的表示形式。

-The Point about killing performance when remapping is on process , it's because that on the first run , EF loads metadata into memory and that takes time as it builds in-memory representation of model from edmx file.

这篇关于实体框架VS纯Ado.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 00:29
查看更多