简体   繁体   English

ADO.NET实体框架或ADO.NET

[英]ADO.NET Entity Framework or ADO.NET

I'm starting a new project based on ASP.NET and Windows server . 我正在开始一个基于ASP.NET和Windows服务器的新项目。

The application is planned to be pretty big and serve large amount of clients pulling and updating high freq. 该应用程序计划相当大,并为大量客户提供高频率和高频率。 changing data. 改变数据。

I have previously created projects with Linq-To-Sql or with Ado.Net . 我之前使用Linq-To-Sql或Ado.Net创建了项目。

My plan for this project is to use VS2010 and the new EF4 framework. 我对这个项目的计划是使用VS2010和新的EF4框架。

  • It would be great to hear other programmers options about development with Entity Framework 听到其他程序员关于使用Entity Framework进行开发的选项会很棒

  • Pros and cons from previous experience? 以往经验的利弊?

  • Do you think EF4 is ready for production? 您认为EF4是否已准备好投入生产?

  • Should i take the risk or just stick with plain old good ADO.NET? 我应该冒风险还是坚持使用普通的旧ADO.NET?

Whether EF4 is really ready for production is a bit hard to say since it's not officially been released yet.... but all the preliminary experiences and reports about it seem to indicate it's quite good. EF4是否真的准备好生产有点难以说明,因为它还没有正式发布......但所有的初步经验和报告似乎都表明它非常好。

However: you need to take into consideration what EF is trying to solve; 但是:你需要考虑EF试图解决的问题; it's a two-layer approach, one layer maps to your physical storage schema in your database (and supports multiple backends), and the second layer is your conceptual model you program against. 它是一个双层方法,一层映射到数据库中的物理存储架构(并支持多个后端),第二层是您编程的概念模型。 And of course, there's the need for a mapping between those two layers. 当然,需要在这两个层之间进行映射。

So EF4 is great if you have a large number of tables, if you have multiple backends to support, if you need to be able to map a physical schema to a different conceptual schema, and so forth. 因此,如果您有大量的表,如果您有多个后端需要支持,如果您需要能够将物理模式映射到不同的概念模式,那么EF4非常棒,等等。 It's great for complex enterprise level applications. 它非常适合复杂的企业级应用程序。

BUT that comes at a cost - those extra layers do have an impact on performance, complexity, maintainability. 但这需要付出代价 - 这些额外的层确实会对性能,复杂性和可维护性产生影响。 If you need those features, you'll be happy to pay that price, no question. 如果您需要这些功能,您将很乐意支付这个价格,毫无疑问。 But do you need that?? 但你需要吗?

Sure, you could go back to straight ADO.NET - but do you really want to fiddle around with DataTables, DataRows, and untyped Row["RowName"] constructs again?? 当然,你可以回到直接的ADO.NET - 但你真的想再次使用DataTables,DataRows和无类型的Row["RowName"]构造? REALLY??? 真???

So my recommendation would be this: 所以我的建议如下:

  • if you need only SQL Server as your backend 如果您只需要SQL Server作为后端
  • if you have a fairly simple and straightforward mapping of one database table to one entity object in your model 如果您有一个相当简单和直接的映射,将一个数据库表映射到模型中的一个实体对象

then: use Linq-to-SQL ! 然后:使用Linq-to-SQL Why not?? 为什么不?? It's still totally supported by Microsoft in .NET 4 - heck, they even did bugfixes and added a few bits and pieces - it's fast, it's efficient, it's lean and mean - so why not?? 它仍然完全得到微软在.NET 4中的支持 - 哎呀,他们甚至做了错误修正并添加了一些零碎的东西 - 它很快,它很有效,它很精简和平均 - 所以为什么不呢?

My advice is use both. 我的建议是同时使用。 At first I thought I would only use linq to sql and never have to touch ado.net ever again ( what made me happy lol). 起初我以为我只会使用linq来sql而且永远不必再次触摸ado.net(是什么让我开心大笑)。

Now I am using both because some things linq to sql(and any ORM like EF) can't do. 现在我正在使用两者,因为有些东西linq to sql(和任何像EF这样的ORM)都做不到。 I had to do some mass inserts and I did it first with linq to sql and to do 500 records it took over 6mins(2 mins for validation rules rest was inserting into the db). 我不得不做一些大量插入,我首先使用linq到sql做了500次记录,花了6分钟(验证规则休息2分钟就是插入数据库)。

I changed it to sql bulk copy and now it is down to 2min and 4 seconds(4 seconds to do all inserts) 我将其更改为sql批量复制,现在它已降至2分4秒(所有插入时间为4秒)

But like marc_s said I really did not want to fiddle around with DataTables, DataRows, and untyped Row["RowName"]. 但是就像marc_s说我真的不想摆弄DataTables,DataRows和无类型的Row [“RowName”]。

Say my table was like 10 columns long and called Table A. What I did was I used linq to sql and made a Table A class( new TableA()) object and populated it with data. 假设我的表格长达10列并且称为表A.我做的是我使用linq to sql并创建了一个表A类(新的TableA())对象并用数据填充它。 I then would pass this object to a method that created the datarow. 然后我将此对象传递给创建数据行的方法。

So linq to sql saved me some time because I probably would have made a class as I would not have wanted to pass in 10 parameters into the method that makes the data row. 因此linq to sql节省了一些时间,因为我可能会创建一个类,因为我不想将10个参数传递给产生数据行的方法。 I also feel it gives a bit of typeness back as you have to pass in the right object to use that method so less chance of passing in the wrong data. 我也觉得它给了一些类型,因为你必须传递正确的对象来使用该方法,因此传递错误数据的机会更少。

Finally you can still use linq to sql to call Stored procedures and that is like one line of code. 最后,您仍然可以使用linq to sql来调用存储过程,这就像一行代码。

So I would use both when ever you notice that linq to sql (or in your case EF) is slow then just write a SP and call it through EF. 因此,当你注意到linq到sql(或者在你的情况下为EF)很慢时,我会使用两者,然后只需编写SP并通过EF调用它。 If you need to do straight ado.net evaluate what you need to do maybe you can use EF for most of the code(so you can at least work with objects) and only for that small portion ado.net sort of what I did with sql bulk copy. 如果你需要直接做ado.net评估你需要做什么,也许你可以在大多数代码中使用EF(所以你至少可以使用对象),而且只用于ado.net的那一小部分我用的是什么sql批量复制。

EF 4 is now more similar to LINQ to SQL, in the good ways; EF 4现在更像是LINQ to SQL,在很好的方面; it has the FK keys right in the object, has add methods right in the object sets, and a lot of other nice features. 它在对象中有FK键,在对象集中添加​​方法,以及许多其他不错的功能。 THe designer is much improved, and the major plus is that it works with SQL and Oracle, and maybe some others (as long as the provider supports it) instead of LINQ to SQL with only SQL Server. 设计人员得到了很大的改进,主要的优点是它可以与SQL和Oracle一起使用,也许还有其他一些(只要提供者支持它),而不是仅使用SQL Server的LINQ to SQL。

EF is the future; EF是未来; the ADO.NET data services is a web service add on, plus it supports POCO and T4 generation, and any new features will support this (LINQ to SQL is maintenance only, and data sets won't be getting any changes any more). ADO.NET数据服务是一个Web服务添加,并且它支持POCO和T4生成,并且任何新功能都将支持此功能(LINQ to SQL仅维护,数据集将不再获得任何更改)。

HTH. HTH。

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

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