codedocu.de

SQL Entity Unterschied:
 
Was ist der Unterschied der beiden Aufrufe eines Datensatzes in C# Entity Framework
Bei der Übersetzung zur Datenbank Abfrage in SQL Server
 
Abfrage 1:  FindAsync(ID)

//*get matching Article from Database by ID
var dbArticle = await _dbContext.tbl_Articles.FindAsync(id);
//*SELECT TOP(1) IDArticle,Title FROM tbl_Articles AS t WHERE IDArticle = @p_0

 
Abfrage 2:  FirstOrDefaultAsync(x=>x.IDArticle==id);

_dbContext.tbl_Articles.FirstOrDefaultAsync(x=>x.IDArticle==id);
//*SELECT TOP(1) IDArticle,Title FROM tbl_Articles AS t WHERE IDArticle = @p_0
//*first db call ~43ms second call ~5ms

 
Beide SQL Abfragen folgen wie hier

SELECT TOP(1) [t].[IDArticle], [t].[Title]
FROM [tbl_Articles] AS [t]
WHERE [t].[IDArticle] = @__p_0
 

 
 
Fazit:
Beide EF Abfragen erfolgen in einer DBCommand SQL Abfrage mit SELECT TOP(1)
Und sind somit identisch  in der Geschwindigkeit
 
SQL Entity Unterschied .FindAsync(ID) und .FirstOrDefaultAsync(x= x.IDArticle==id);
 

info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (42ms) [Parameters=[@__p_0='?' (DbType = Int32)], CommandType='Text', CommandTimeout='30']
SELECT TOP(1) [t].[IDArticle], [t].[Title]
FROM [tbl_Articles] AS [t]
WHERE [t].[IDArticle] = @__p_0
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (5ms) [Parameters=[@__p_0='?' (DbType = Int32)], CommandType='Text', CommandTimeout='30']
SELECT TOP(1) [t].[IDArticle], [t].[Title]
FROM [tbl_Articles] AS [t]
WHERE [t].[IDArticle] = @__p_0

 

Software Entwicklung Stuttgart Nürtingen
Suche Projekte C#, WPF, Windows App,ASP.Net, vb.Net, WinForms, SQL Server, Access, Excel