I am using EF Core 3.1
with SQL Server
provider. If not specified otherwise EF Core
uses generated values for entity keys. (The key is being generated by the provider, in this case SQL Server
) In following documentation page I found statement that:
For example, when using SQL Server, values will be automatically generated for GUID properties (using the SQL Server sequential GUID algorithm)
I was using SQL Profiler
to investigate EF core generated queries and I noticed that for adding an entity it generated following SQL
:
exec sp_executesql N'SET NOCOUNT ON;
INSERT INTO [MySchema].[MyTable] ([Id], ...)
VALUES (@p0, ...);
',N'@p0 uniqueidentifier, ...',@p0='B3DC06A3-2B58-46A0-9085-7A17B064433F', ...
here I see that query already has GUID
in the query, meaning that it obtains it before generating the query. But I have't noticed any attidional calls in SQL Profiler
.
How does the generated values work behind the hood?