简体   繁体   English

EF Core 与 ADO.NET

[英]EF Core vs ADO.NET

One of my customer is developing a set of ASP.NET Core API's which has to support 15,00,000 requests per hour.我的一个客户正在开发一组 ASP.NET 核心 API,它必须支持每小时 15,00,000 个请求。

All the request will end up interacting with SQL Server tables.所有请求最终都将与 SQL 服务器表进行交互。 Some are SQL Server In-Memory OLTP tables.有些是 SQL 服务器内存中 OLTP 表。

The customer is currently using ADO.Net and Stored Procedures to make SQL connectivity in similar application and wondering if they continue using the same or should consider EF Core.客户目前正在使用 ADO.Net 和存储过程在类似的应用程序中建立 SQL 连接,并想知道他们是否继续使用相同的或应该考虑使用 EF Core。

I myself have mostly used ADO.Net in past so wanted to check if we can suggest EF Core here or sticking to ADO.Net with SP is the safest bet?我自己过去主要使用 ADO.Net,所以想检查我们是否可以在这里建议 EF Core 或坚持使用 SP 的 ADO.Net 是最安全的选择?

I know that ADO.NET is the safest choice if you are committed to using Stored Procedures and have a extreme performance requirements, but EF is still relevant in the market and is being used by many.我知道 ADO.NET 是最安全的选择,如果您致力于使用存储过程并有极端的性能要求,但 EF 在市场上仍然很重要并且被许多人使用。 If it was actually so bad it would surely have had an alternative or would have been scrapped.如果它真的如此糟糕,它肯定会有替代品或被废弃。

So is ADO.NET safe bet or we can move on with new technological advancements like EF Core as an ORM and use it with LINQ functionalities, writing less code etc.? ADO.NET 是安全的赌注,还是我们可以继续使用新技术进步,例如 EF Core 作为 ORM 并将其与 LINQ 功能一起使用,编写更少的代码等?

What to do?该怎么办?

is ADO.NET safe bet or we can move on with new technological advancements like EF Core as an ORM and use it with LINQ functionalities, writing less code etc.? ADO.NET 是安全的赌注,还是我们可以继续使用新技术进步,如 EF Core 作为 ORM 并将其与 LINQ 功能一起使用,编写更少的代码等?

We cannot make a decision based on one stat (15,000,000), but one option is to migrate/extend with an ORM part by part.我们无法根据一个统计数据 (15,000,000) 做出决定,但一种选择是使用 ORM 逐个迁移/扩展。 You can maintain existing code and add new functionality using an ORM.您可以使用 ORM 维护现有代码并添加新功能。 As you gain experience you can make better decision.随着经验的积累,您可以做出更好的决定。


or should consider EF Core或者应该考虑 EF Core

I suppose one should always consider available contemporary technologies upon starting a significant piece of work but it would be irresponsible to say that all new projects should be written in [insert_some_framework_here].我想人们应该在开始一项重要工作时始终考虑可用的当代技术,但是说所有新项目都应该写在 [insert_some_framework_here] 中是不负责任的。

EF Core and stored procs EF Core 和存储过程

The following executes a stored procedure in EF Core.下面在 EF Core 中执行一个存储过程。

var blogs = context.Blogs
    .FromSqlRaw("EXECUTE dbo.GetMostPopularBlogs")
    .ToList();

Please note that:请注意:

  • it can be mixed and matched it with Linq queries它可以与 Linq 查询混合和匹配
  • there are limitations有限制

Please see Raw SQL Queries .请参阅原始 SQL 查询


Dapper and stored procs Dapper 和存储过程

Have you considered Dapper ?你考虑过Dapper吗? The following is directly from its official repo.以下直接来自其官方回购。

Dapper fully supports stored procs: Dapper 完全支持存储过程:

 var user = cnn.Query<User>("spGetUser", new {Id = 1}, commandType: CommandType.StoredProcedure).SingleOrDefault();

If you want something more fancy, you can do:如果你想要更花哨的东西,你可以这样做:

 var p = new DynamicParameters(); p.Add("@a", 11); p.Add("@b", dbType: DbType.Int32, direction: ParameterDirection.Output); p.Add("@c", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue); cnn.Execute("spMagicProc", p, commandType: CommandType.StoredProcedure); int b = p.Get<int>("@b"); int c = p.Get<int>("@c");

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

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