try
{
var businessPartner = dbTarget.BusinessPartners
.Include(bp => bp.BPLayerXScrapers)
.FirstOrDefault(bp => bp.Name == name);
if (businessPartner == null)
{
throw new KeyNotFoundException("BusinessPartner not found.");
}
if (businessPartner == null)
{
Console.WriteLine("BusinessPartner not found.");
return; // Or handle the absence of BusinessPartner accordingly
}
BPLayerXScraper newScraper = new BPLayerXScraper
{
Hash = "abc123",
LinksOnTheLandingPage = 10,
Heading = "Fantasy Heading",
Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
URL = "https://example.com",
Layer = 3,
Links = new List { "https://example.com/link1", "https://example.com/link2" },
TimeStampCreated = DateTime.UtcNow,
TimeStampUpdated = DateTime.UtcNow.AddDays(1)
};
// Adding the new scraper to the BusinessPartner's collection of scrapers
businessPartner.BPLayerXScrapers.Add(newScraper);
// Saving changes in the database
dbTarget.SaveChanges();
}
catch (DbUpdateConcurrencyException ex)
{
Console.WriteLine("A concurrency conflict occurred. Handling...");
// Handling concurrency exception specifically for updates to BPLayerXScrapers or BusinessPartner
foreach (var entry in ex.Entries)
{
var databaseValues = entry.GetDatabaseValues();
if (databaseValues != null)
{
entry.OriginalValues.SetValues(databaseValues);
}
else
{
// It hits here, even the object is presented in the database
Console.WriteLine("The object was deleted from the database.");
}
}
dbTarget.SaveChanges();
}
catch (Exception e)
{
Console.WriteLine($"An error occurred: {e.Message}");
}
It fails with:
Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException: 'The
database operation was expected to affect 1 row(s), but actually
affected 0 row(s); data may have been modified or deleted since
entities were loaded. See https://go.microsoft.com/fwlink/?LinkId=527962 for information on
understanding and handling optimistic concurrency exceptions.'
Logging:
dbug: 20.04.2024 09:29:06.184 CoreEventId.SaveChangesStarting[10004] (Microsoft.EntityFrameworkCore.Update)
SaveChanges starting for 'DbTestingCSharp'.
dbug: 20.04.2024 09:29:06.187 CoreEventId.DetectChangesStarting[10800] (Microsoft.EntityFrameworkCore.ChangeTracking)
DetectChanges starting for 'DbTestingCSharp'.
dbug: 20.04.2024 09:29:06.205 CoreEventId.CollectionChangeDetected[10804] (Microsoft.EntityFrameworkCore.ChangeTracking)
1 entities were added and 0 entities were removed from navigation 'BusinessPartner.BPLayerXScrapers'. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see key values.
dbug: 20.04.2024 09:29:06.231 CoreEventId.ForeignKeyChangeDetected[10803] (Microsoft.EntityFrameworkCore.ChangeTracking)
The foreign key property 'BPLayerXScraper.BusinessPartnerId' was detected as changed. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see property values.
dbug: 20.04.2024 09:29:06.237 CoreEventId.StartedTracking[10806] (Microsoft.EntityFrameworkCore.ChangeTracking)
Context 'DbTestingCSharp' started tracking 'BPLayerXScraper' entity. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see key values.
dbug: 20.04.2024 09:29:06.240 CoreEventId.DetectChangesCompleted[10801] (Microsoft.EntityFrameworkCore.ChangeTracking)
DetectChanges completed for 'DbTestingCSharp'.
dbug: 20.04.2024 09:29:06.273 RelationalEventId.ConnectionOpening[20000] (Microsoft.EntityFrameworkCore.Database.Connection)
Opening connection to database 'xTesting' on server 'xxxx'.
dbug: 20.04.2024 09:29:06.275 RelationalEventId.ConnectionOpened[20001] (Microsoft.EntityFrameworkCore.Database.Connection)
Opened connection to database 'xTesting' on server 'xxxx'.
dbug: 20.04.2024 09:29:06.277 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command)
Creating DbCommand for 'ExecuteReader'.
dbug: 20.04.2024 09:29:06.279 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
Created DbCommand for 'ExecuteReader' (1ms).
dbug: 20.04.2024 09:29:06.280 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command)
Initialized DbCommand for 'ExecuteReader' (2ms).
dbug: 20.04.2024 09:29:06.282 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
Executing DbCommand [Parameters=[@p9='?' (DbType = Guid), @p0='?' (DbType = Guid), @p1='?' (Size = 4000), @p2='?' (Size = 4000), @p3='?' (DbType = Int32), @p4='?' (DbType = Int32), @p5='?' (Size = 4000), @p6='?' (DbType = DateTime2), @p7='?' (DbType = DateTime2), @p8='?' (Size = 4000)], CommandType='Text', CommandTimeout='30']
SET IMPLICIT_TRANSACTIONS OFF;
SET NOCOUNT ON;
UPDATE [BPLayerXScrapers] SET [BusinessPartnerId] = @p0, [Hash] = @p1, [Heading] = @p2, [Layer] = @p3, [LinksOnTheLandingPage] = @p4, [Text] = @p5, [TimeStampCreated] = @p6, [TimeStampUpdated] = @p7, = @p8
OUTPUT 1
WHERE [Id] = @p9;
info: ... orkcore-db
Я добавил: [code][Timestamp] public byte[] Version { get; set; } // optimistic concurrency [/code] Я записал соответствующий код: DBCOntext: [code] public class DbTestingCSharp : DbContext { public DbSet BusinessPartners { get; set; } public DbSet BPLayerXScrapers { get; set; }
if (businessPartner == null) { throw new KeyNotFoundException("BusinessPartner not found."); }
if (businessPartner == null) { Console.WriteLine("BusinessPartner not found."); return; // Or handle the absence of BusinessPartner accordingly }
BPLayerXScraper newScraper = new BPLayerXScraper { Hash = "abc123", LinksOnTheLandingPage = 10, Heading = "Fantasy Heading", Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", URL = "https://example.com", Layer = 3, Links = new List { "https://example.com/link1", "https://example.com/link2" }, TimeStampCreated = DateTime.UtcNow, TimeStampUpdated = DateTime.UtcNow.AddDays(1) };
// Adding the new scraper to the BusinessPartner's collection of scrapers businessPartner.BPLayerXScrapers.Add(newScraper);
// Saving changes in the database dbTarget.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { Console.WriteLine("A concurrency conflict occurred. Handling...");
// Handling concurrency exception specifically for updates to BPLayerXScrapers or BusinessPartner foreach (var entry in ex.Entries) { var databaseValues = entry.GetDatabaseValues(); if (databaseValues != null) { entry.OriginalValues.SetValues(databaseValues); } else { // It hits here, even the object is presented in the database Console.WriteLine("The object was deleted from the database."); } }
Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException: 'The database operation was expected to affect 1 row(s), but actually affected 0 row(s); data may have been modified or deleted since entities were loaded. See https://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions.'
Logging:
dbug: 20.04.2024 09:29:06.184 CoreEventId.SaveChangesStarting[10004] (Microsoft.EntityFrameworkCore.Update) SaveChanges starting for 'DbTestingCSharp'. dbug: 20.04.2024 09:29:06.187 CoreEventId.DetectChangesStarting[10800] (Microsoft.EntityFrameworkCore.ChangeTracking) DetectChanges starting for 'DbTestingCSharp'. dbug: 20.04.2024 09:29:06.205 CoreEventId.CollectionChangeDetected[10804] (Microsoft.EntityFrameworkCore.ChangeTracking) 1 entities were added and 0 entities were removed from navigation 'BusinessPartner.BPLayerXScrapers'. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see key values. dbug: 20.04.2024 09:29:06.231 CoreEventId.ForeignKeyChangeDetected[10803] (Microsoft.EntityFrameworkCore.ChangeTracking) The foreign key property 'BPLayerXScraper.BusinessPartnerId' was detected as changed. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see property values. dbug: 20.04.2024 09:29:06.237 CoreEventId.StartedTracking[10806] (Microsoft.EntityFrameworkCore.ChangeTracking) Context 'DbTestingCSharp' started tracking 'BPLayerXScraper' entity. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see key values. dbug: 20.04.2024 09:29:06.240 CoreEventId.DetectChangesCompleted[10801] (Microsoft.EntityFrameworkCore.ChangeTracking) DetectChanges completed for 'DbTestingCSharp'. dbug: 20.04.2024 09:29:06.273 RelationalEventId.ConnectionOpening[20000] (Microsoft.EntityFrameworkCore.Database.Connection) Opening connection to database 'xTesting' on server 'xxxx'. dbug: 20.04.2024 09:29:06.275 RelationalEventId.ConnectionOpened[20001] (Microsoft.EntityFrameworkCore.Database.Connection) Opened connection to database 'xTesting' on server 'xxxx'. dbug: 20.04.2024 09:29:06.277 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command) Creating DbCommand for 'ExecuteReader'. dbug: 20.04.2024 09:29:06.279 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command) Created DbCommand for 'ExecuteReader' (1ms). dbug: 20.04.2024 09:29:06.280 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command) Initialized DbCommand for 'ExecuteReader' (2ms). dbug: 20.04.2024 09:29:06.282 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command) Executing DbCommand [Parameters=[@p9='?' (DbType = Guid), @p0='?' (DbType = Guid), @p1='?' (Size = 4000), @p2='?' (Size = 4000), @p3='?' (DbType = Int32), @p4='?' (DbType = Int32), @p5='?' (Size = 4000), @p6='?' (DbType = DateTime2), @p7='?' (DbType = DateTime2), @p8='?' (Size = 4000)], CommandType='Text', CommandTimeout='30'] SET IMPLICIT_TRANSACTIONS OFF; SET NOCOUNT ON; UPDATE [BPLayerXScrapers] SET [BusinessPartnerId] = @p0, [Hash] = @p1, [Heading] = @p2, [Layer] = @p3, [LinksOnTheLandingPage] = @p4, [Text] = @p5, [TimeStampCreated] = @p6, [TimeStampUpdated] = @p7, [URL] = @p8 OUTPUT 1 WHERE [Id] = @p9; info: 20.04.2024 09:29:06.301 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command) Executed DbCommand (19ms) [Parameters=[@p9='?' (DbType = Guid), @p0='?' (DbType = Guid), @p1='?' (Size = 4000), @p2='?' (Size = 4000), @p3='?' (DbType = Int32), @p4='?' (DbType = Int32), @p5='?' (Size = 4000), @p6='?' (DbType = DateTime2), @p7='?' (DbType = DateTime2), @p8='?' (Size = 4000)], CommandType='Text', CommandTimeout='30'] SET IMPLICIT_TRANSACTIONS OFF; SET NOCOUNT ON; UPDATE [BPLayerXScrapers] SET [BusinessPartnerId] = @p0, [Hash] = @p1, [Heading] = @p2, [Layer] = @p3, [LinksOnTheLandingPage] = @p4, [Text] = @p5, [TimeStampCreated] = @p6, [TimeStampUpdated] = @p7, [URL] = @p8 OUTPUT 1 WHERE [Id] = @p9; dbug: 20.04.2024 09:29:06.309 CoreEventId.OptimisticConcurrencyException[10006] (Microsoft.EntityFrameworkCore.Update) Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException: The database operation was expected to affect 1 row(s), but actually affected 0 row(s); data may have been modified or deleted since entities were loaded. See https://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions. dbug: 20.04.2024 09:29:06.312 RelationalEventId.DataReaderClosing[20301] (Microsoft.EntityFrameworkCore.Database.Command) Closing data reader to 'xTesting' on server 'xxxx'. dbug: 20.04.2024 09:29:06.313 RelationalEventId.DataReaderDisposing[20300] (Microsoft.EntityFrameworkCore.Database.Command) A data reader for 'xTesting' on server 'xxxx' is being disposed after spending 10ms reading results. dbug: 20.04.2024 09:29:06.315 RelationalEventId.ConnectionClosing[20002] (Microsoft.EntityFrameworkCore.Database.Connection) Closing connection to database 'xTesting' on server 'xxxx'. dbug: 20.04.2024 09:29:06.316 RelationalEventId.ConnectionClosed[20003] (Microsoft.EntityFrameworkCore.Database.Connection) Closed connection to database 'xTesting' on server 'xxxx' (1ms). Exception thrown: 'Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException' in Microsoft.EntityFrameworkCore.dll dbug: 20.04.2024 09:29:06.337 CoreEventId.QueryCompilationStarting[10111] (Microsoft.EntityFrameworkCore.Query) Compiling query expression: 'DbSet() .AsNoTracking() .IgnoreQueryFilters() .Where(e => object.Equals( objA: EF.Property(e, "Id"), objB: __get_Item_0)) .Select(e => new object[] { (object)(Guid)EF.Property(e, "Id"), (object)(Guid?)EF.Property(e, "BusinessPartnerId"), (object)(string)EF.Property(e, "Hash"), (object)(string)EF.Property(e, "Heading"), (object)(int)EF.Property(e, "Layer"), (object)(int)EF.Property(e, "LinksOnTheLandingPage"), (object)(string)EF.Property(e, "Text"), (object)(DateTime)EF.Property(e, "TimeStampCreated"), (object)(DateTime?)EF.Property(e, "TimeStampUpdated"), (object)(string)EF.Property(e, "URL") }) .FirstOrDefault()' dbug: 20.04.2024 09:29:06.345 CoreEventId.QueryExecutionPlanned[10107] (Microsoft.EntityFrameworkCore.Query) Generated query execution expression: 'queryContext => new SingleQueryingEnumerable( (RelationalQueryContext)queryContext, RelationalCommandCache.QueryExpression( Client Projections: 0 -> 0 1 -> 1 2 -> 2 3 -> 3 4 -> 4 5 -> 5 6 -> 6 7 -> 7 8 -> 8 9 -> 9 SELECT TOP(1) b.Id, b.BusinessPartnerId, b.Hash, b.Heading, b.Layer, b.LinksOnTheLandingPage, b.Text, b.TimeStampCreated, b.TimeStampUpdated, b.URL FROM BPLayerXScrapers AS b WHERE b.Id == @__get_Item_0), null, Func, DbTesting.DbTestingCSharp, False, False, True ) .SingleOrDefault()' dbug: 20.04.2024 09:29:06.348 RelationalEventId.ConnectionOpening[20000] (Microsoft.EntityFrameworkCore.Database.Connection) Opening connection to database 'xTesting' on server 'xxxx'. dbug: 20.04.2024 09:29:06.349 RelationalEventId.ConnectionOpened[20001] (Microsoft.EntityFrameworkCore.Database.Connection) Opened connection to database 'xTesting' on server 'xxxx'. dbug: 20.04.2024 09:29:06.351 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command) Creating DbCommand for 'ExecuteReader'. dbug: 20.04.2024 09:29:06.353 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command) Created DbCommand for 'ExecuteReader' (1ms). dbug: 20.04.2024 09:29:06.354 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command) Initialized DbCommand for 'ExecuteReader' (3ms). dbug: 20.04.2024 09:29:06.355 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command) Executing DbCommand [Parameters=[@__get_Item_0='?' (DbType = Guid)], CommandType='Text', CommandTimeout='30'] SELECT TOP(1) [b].[Id], [b].[BusinessPartnerId], [b].[Hash], [b].[Heading], [b].[Layer], [b].[LinksOnTheLandingPage], [b].[Text], [b].[TimeStampCreated], [b].[TimeStampUpdated], [b].[URL] FROM [BPLayerXScrapers] AS [b] WHERE [b].[Id] = @__get_Item_0 info: 20.04.2024 09:29:06.359 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command) Executed DbCommand (3ms) [Parameters=[@__get_Item_0='?' (DbType = Guid)], CommandType='Text', CommandTimeout='30'] SELECT TOP(1) [b].[Id], [b].[BusinessPartnerId], [b].[Hash], [b].[Heading], [b].[Layer], [b].[LinksOnTheLandingPage], [b].[Text], [b].[TimeStampCreated], [b].[TimeStampUpdated], [b].[URL] FROM [BPLayerXScrapers] AS [b] WHERE [b].[Id] = @__get_Item_0 dbug: 20.04.2024 09:29:06.360 RelationalEventId.DataReaderClosing[20301] (Microsoft.EntityFrameworkCore.Database.Command) Closing data reader to 'xTesting' on server 'xxxx'. dbug: 20.04.2024 09:29:06.361 RelationalEventId.DataReaderDisposing[20300] (Microsoft.EntityFrameworkCore.Database.Command) A data reader for 'xTesting' on server 'xxxx' is being disposed after spending 1ms reading results. dbug: 20.04.2024 09:29:06.362 RelationalEventId.ConnectionClosing[20002] (Microsoft.EntityFrameworkCore.Database.Connection) Closing connection to database 'xTesting' on server 'xxxx'. dbug: 20.04.2024 09:29:06.364 RelationalEventId.ConnectionClosed[20003] (Microsoft.EntityFrameworkCore.Database.Connection) Closed connection to database 'xTesting' on server 'xxxx' (1ms). dbug: 20.04.2024 09:29:06.365 CoreEventId.SaveChangesStarting[10004] (Microsoft.EntityFrameworkCore.Update) SaveChanges starting for 'DbTestingCSharp'. dbug: 20.04.2024 09:29:06.366 CoreEventId.DetectChangesStarting[10800] (Microsoft.EntityFrameworkCore.ChangeTracking) DetectChanges starting for 'DbTestingCSharp'. dbug: 20.04.2024 09:29:06.369 CoreEventId.DetectChangesCompleted[10801] (Microsoft.EntityFrameworkCore.ChangeTracking) DetectChanges completed for 'DbTestingCSharp'. dbug: 20.04.2024 09:29:06.371 RelationalEventId.ConnectionOpening[20000] (Microsoft.EntityFrameworkCore.Database.Connection) Opening connection to database 'xTesting' on server 'xxxx'. dbug: 20.04.2024 09:29:06.373 RelationalEventId.ConnectionOpened[20001] (Microsoft.EntityFrameworkCore.Database.Connection) Opened connection to database 'xTesting' on server 'xxxx'. dbug: 20.04.2024 09:29:06.374 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command) Creating DbCommand for 'ExecuteReader'. dbug: 20.04.2024 09:29:06.375 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command) Created DbCommand for 'ExecuteReader' (1ms). dbug: 20.04.2024 09:29:06.376 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command) Initialized DbCommand for 'ExecuteReader' (2ms). dbug: 20.04.2024 09:29:06.377 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command) Executing DbCommand [Parameters=[@p9='?' (DbType = Guid), @p0='?' (DbType = Guid), @p1='?' (Size = 4000), @p2='?' (Size = 4000), @p3='?' (DbType = Int32), @p4='?' (DbType = Int32), @p5='?' (Size = 4000), @p6='?' (DbType = DateTime2), @p7='?' (DbType = DateTime2), @p8='?' (Size = 4000)], CommandType='Text', CommandTimeout='30'] SET IMPLICIT_TRANSACTIONS OFF; SET NOCOUNT ON; UPDATE [BPLayerXScrapers] SET [BusinessPartnerId] = @p0, [Hash] = @p1, [Heading] = @p2, [Layer] = @p3, [LinksOnTheLandingPage] = @p4, [Text] = @p5, [TimeStampCreated] = @p6, [TimeStampUpdated] = @p7, [URL] = @p8 OUTPUT 1 WHERE [Id] = @p9; info: 20.04.2024 09:29:06.379 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command) Executed DbCommand (2ms) [Parameters=[@p9='?' (DbType = Guid), @p0='?' (DbType = Guid), @p1='?' (Size = 4000), @p2='?' (Size = 4000), @p3='?' (DbType = Int32), @p4='?' (DbType = Int32), @p5='?' (Size = 4000), @p6='?' (DbType = DateTime2), @p7='?' (DbType = DateTime2), @p8='?' (Size = 4000)], CommandType='Text', CommandTimeout='30'] SET IMPLICIT_TRANSACTIONS OFF; SET NOCOUNT ON; UPDATE [BPLayerXScrapers] SET [BusinessPartnerId] = @p0, [Hash] = @p1, [Heading] = @p2, [Layer] = @p3, [LinksOnTheLandingPage] = @p4, [Text] = @p5, [TimeStampCreated] = @p6, [TimeStampUpdated] = @p7, [URL] = @p8 OUTPUT 1 WHERE [Id] = @p9; dbug: 20.04.2024 09:29:06.381 CoreEventId.OptimisticConcurrencyException[10006] (Microsoft.EntityFrameworkCore.Update) Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException: The database operation was expected to affect 1 row(s), but actually affected 0 row(s); data may have been modified or deleted since entities were loaded. See https://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions. dbug: 20.04.2024 09:29:06.383 RelationalEventId.DataReaderClosing[20301] (Microsoft.EntityFrameworkCore.Database.Command) Closing data reader to 'xTesting' on server 'xxxx'. dbug: 20.04.2024 09:29:06.384 RelationalEventId.DataReaderDisposing[20300] (Microsoft.EntityFrameworkCore.Database.Command) A data reader for 'xTesting' on server 'xxxx' is being disposed after spending 2ms reading results. dbug: 20.04.2024 09:29:06.385 RelationalEventId.ConnectionClosing[20002] (Microsoft.EntityFrameworkCore.Database.Connection) Closing connection to database 'xTesting' on server 'xxxx'. dbug: 20.04.2024 09:29:06.386 RelationalEventId.ConnectionClosed[20003] (Microsoft.EntityFrameworkCore.Database.Connection) Closed connection to database 'xTesting' on server 'xxxx' (1ms). Exception thrown: 'Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException' in Microsoft.EntityFrameworkCore.dll An unhandled exception of type 'Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException' occurred in Microsoft.EntityFrameworkCore.dll The database operation was expected to affect 1 row(s), but actually affected 0 row(s); data may have been modified or deleted since entities were loaded. See https://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions.
Sensitive Logging:
dbug: 20.04.2024 09:36:45.145 CoreEventId.SaveChangesStarting[10004] (Microsoft.EntityFrameworkCore.Update) SaveChanges starting for 'DbTestingCSharp'. dbug: 20.04.2024 09:36:45.148 CoreEventId.DetectChangesStarting[10800] (Microsoft.EntityFrameworkCore.ChangeTracking) DetectChanges starting for 'DbTestingCSharp'. dbug: 20.04.2024 09:36:45.165 CoreEventId.CollectionChangeDetected[10804] (Microsoft.EntityFrameworkCore.ChangeTracking) 1 entities were added and 0 entities were removed from navigation 'BusinessPartner.BPLayerXScrapers' on entity with key '{Id: f7e9aec7-c04c-41e2-aad1-b1283536c32e}'. dbug: 20.04.2024 09:36:45.192 CoreEventId.ForeignKeyChangeDetected[10803] (Microsoft.EntityFrameworkCore.ChangeTracking) The foreign key property 'BPLayerXScraper.BusinessPartnerId' was detected as changed from '(null)' to 'f7e9aec7-c04c-41e2-aad1-b1283536c32e' for entity with key '{Id: ab313081-5c02-4e60-98b2-bc651ba737fd}'. dbug: 20.04.2024 09:36:45.198 CoreEventId.StartedTracking[10806] (Microsoft.EntityFrameworkCore.ChangeTracking) Context 'DbTestingCSharp' started tracking 'BPLayerXScraper' entity with key '{Id: ab313081-5c02-4e60-98b2-bc651ba737fd}'. dbug: 20.04.2024 09:36:45.200 CoreEventId.DetectChangesCompleted[10801] (Microsoft.EntityFrameworkCore.ChangeTracking) DetectChanges completed for 'DbTestingCSharp'. dbug: 20.04.2024 09:36:45.236 RelationalEventId.ConnectionOpening[20000] (Microsoft.EntityFrameworkCore.Database.Connection) Opening connection to database 'xTesting' on server 'xxxx'. dbug: 20.04.2024 09:36:45.239 RelationalEventId.ConnectionOpened[20001] (Microsoft.EntityFrameworkCore.Database.Connection) Opened connection to database 'xTesting' on server 'xxxx'. dbug: 20.04.2024 09:36:45.241 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command) Creating DbCommand for 'ExecuteReader'. dbug: 20.04.2024 09:36:45.242 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command) Created DbCommand for 'ExecuteReader' (1ms). dbug: 20.04.2024 09:36:45.244 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command) Initialized DbCommand for 'ExecuteReader' (3ms). dbug: 20.04.2024 09:36:45.247 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command) Executing DbCommand [Parameters=[@p9='ab313081-5c02-4e60-98b2-bc651ba737fd', @p0='f7e9aec7-c04c-41e2-aad1-b1283536c32e' (Nullable = true), @p1='abc123' (Nullable = false) (Size = 4000), @p2='Fantasy Heading' (Nullable = false) (Size = 4000), @p3='3', @p4='10', @p5='Lorem ipsum dolor sit amet, consectetur adipiscing elit.' (Nullable = false) (Size = 4000), @p6='2024-04-20T07:36:31.9677616Z', @p7='2024-04-21T07:36:31.9677827Z' (Nullable = true), @p8='https://example.com' (Nullable = false) (Size = 4000)], CommandType='Text', CommandTimeout='30'] SET IMPLICIT_TRANSACTIONS OFF; SET NOCOUNT ON; UPDATE [BPLayerXScrapers] SET [BusinessPartnerId] = @p0, [Hash] = @p1, [Heading] = @p2, [Layer] = @p3, [LinksOnTheLandingPage] = @p4, [Text] = @p5, [TimeStampCreated] = @p6, [TimeStampUpdated] = @p7, [URL] = @p8 OUTPUT 1 WHERE [Id] = @p9; info: 20.04.2024 09:36:45.256 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command) Executed DbCommand (10ms) [Parameters=[@p9='ab313081-5c02-4e60-98b2-bc651ba737fd', @p0='f7e9aec7-c04c-41e2-aad1-b1283536c32e' (Nullable = true), @p1='abc123' (Nullable = false) (Size = 4000), @p2='Fantasy Heading' (Nullable = false) (Size = 4000), @p3='3', @p4='10', @p5='Lorem ipsum dolor sit amet, consectetur adipiscing elit.' (Nullable = false) (Size = 4000), @p6='2024-04-20T07:36:31.9677616Z', @p7='2024-04-21T07:36:31.9677827Z' (Nullable = true), @p8='https://example.com' (Nullable = false) (Size = 4000)], CommandType='Text', CommandTimeout='30'] SET IMPLICIT_TRANSACTIONS OFF; SET NOCOUNT ON; UPDATE [BPLayerXScrapers] SET [BusinessPartnerId] = @p0, [Hash] = @p1, [Heading] = @p2, [Layer] = @p3, [LinksOnTheLandingPage] = @p4, [Text] = @p5, [TimeStampCreated] = @p6, [TimeStampUpdated] = @p7, [URL] = @p8 OUTPUT 1 WHERE [Id] = @p9; dbug: 20.04.2024 09:36:45.263 CoreEventId.OptimisticConcurrencyException[10006] (Microsoft.EntityFrameworkCore.Update) Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException: The database operation was expected to affect 1 row(s), but actually affected 0 row(s); data may have been modified or deleted since entities were loaded. See https://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions. dbug: 20.04.2024 09:36:45.266 RelationalEventId.DataReaderClosing[20301] (Microsoft.EntityFrameworkCore.Database.Command) Closing data reader to 'xTesting' on server 'xxxx'. dbug: 20.04.2024 09:36:45.268 RelationalEventId.DataReaderDisposing[20300] (Microsoft.EntityFrameworkCore.Database.Command) A data reader for 'xTesting' on server 'xxxx' is being disposed after spending 9ms reading results. dbug: 20.04.2024 09:36:45.270 RelationalEventId.ConnectionClosing[20002] (Microsoft.EntityFrameworkCore.Database.Connection) Closing connection to database 'xTesting' on server 'xxxx'. dbug: 20.04.2024 09:36:45.271 RelationalEventId.ConnectionClosed[20003] (Microsoft.EntityFrameworkCore.Database.Connection) Closed connection to database 'xTesting' on server 'xxxx' (1ms). Exception thrown: 'Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException' in Microsoft.EntityFrameworkCore.dll