Closed stevejackson-daviesgroup closed 1 week ago
I have done some more digging into this, and changed the sample repo to log all EF operations and save the executed SQL commands. This has pointed to the root cause (I believe) but it doesn't make any sense to me. I'm including the full log further down, but I've included a smaller snip from the log that I feel is the pertinent issue.
The sample repo seems to insert the Titles and Homepages data correctly, and starts tracking these entities - as expected - however after inserting the 4 Employee records there are some rather odd entries in the log.
This leads to Employee with ID 1 not being saved to the database (as it was detached) and Employee with ID 3 having no TitleId. Considering that all of the Employee records have the same DefaultHomePageId and of the 4 Title records they are split evenly between the 4 Employee records (2 Employees use TitleId 1 and 2 use TitleId 2) and no data has been requested to be changed between the data being added and the subsequent reads (reads for validation, but the main code this is derived from does need to read inserted data back) this does not make any sense to me at all.
I really hope that somebody can shed some light on this issue as this is currently blocking development.
Log Snippet:
dbug: 15/11/2024 12:36:42.532 CoreEventId.StartedTracking[10806] (Microsoft.EntityFrameworkCore.ChangeTracking)
Context 'DatabaseContext' started tracking 'Employee' entity with key '{Id: 1}'.
dbug: 15/11/2024 12:36:42.533 CoreEventId.ReferenceChangeDetected[10805] (Microsoft.EntityFrameworkCore.ChangeTracking)
The navigation 'Employee.DefaultHomePage' for entity with key '{Id: 2}' was detected as changed.
dbug: 15/11/2024 12:36:42.536 CoreEventId.CascadeDeleteOrphan[10003] (Microsoft.EntityFrameworkCore.Update)
An entity of type 'Employee' with key '{Id: 1}' changed to 'Detached' state due to severed required relationship to its parent entity of type 'HomePage'.
dbug: 15/11/2024 12:36:42.539 CoreEventId.StateChanged[10807] (Microsoft.EntityFrameworkCore.ChangeTracking)
The 'Employee' entity with key '{Id: 1}' tracked by 'DatabaseContext' changed state from 'Added' to 'Detached'.
dbug: 15/11/2024 12:36:42.540 CoreEventId.ReferenceChangeDetected[10805] (Microsoft.EntityFrameworkCore.ChangeTracking)
The navigation 'Employee.Title' for entity with key '{Id: 2}' was detected as changed.
dbug: 15/11/2024 12:36:42.540 CoreEventId.StartedTracking[10806] (Microsoft.EntityFrameworkCore.ChangeTracking)
Context 'DatabaseContext' started tracking 'Employee' entity with key '{Id: 2}'.
dbug: 15/11/2024 12:36:42.540 CoreEventId.ReferenceChangeDetected[10805] (Microsoft.EntityFrameworkCore.ChangeTracking)
The navigation 'Employee.DefaultHomePage' for entity with key '{Id: 3}' was detected as changed.
dbug: 15/11/2024 12:36:42.541 CoreEventId.ReferenceChangeDetected[10805] (Microsoft.EntityFrameworkCore.ChangeTracking)
The navigation 'Employee.Title' for entity with key '{Id: 3}' was detected as changed.
dbug: 15/11/2024 12:36:42.541 CoreEventId.StartedTracking[10806] (Microsoft.EntityFrameworkCore.ChangeTracking)
Context 'DatabaseContext' started tracking 'Employee' entity with key '{Id: 3}'.
dbug: 15/11/2024 12:36:42.541 CoreEventId.ReferenceChangeDetected[10805] (Microsoft.EntityFrameworkCore.ChangeTracking)
The navigation 'Employee.DefaultHomePage' for entity with key '{Id: 4}' was detected as changed.
dbug: 15/11/2024 12:36:42.542 CoreEventId.ReferenceChangeDetected[10805] (Microsoft.EntityFrameworkCore.ChangeTracking)
The navigation 'Employee.Title' for entity with key '{Id: 4}' was detected as changed.
dbug: 15/11/2024 12:36:42.545 CoreEventId.ForeignKeyChangeDetected[10803] (Microsoft.EntityFrameworkCore.ChangeTracking)
The foreign key property 'Employee.TitleId' was detected as changed from '2' to '(null)' for entity with key '{Id: 3}'.
dbug: 15/11/2024 12:36:42.547 CoreEventId.ReferenceChangeDetected[10805] (Microsoft.EntityFrameworkCore.ChangeTracking)
The navigation 'Employee.Title' for entity with key '{Id: 3}' was detected as changed.
dbug: 15/11/2024 12:36:42.547 CoreEventId.StartedTracking[10806] (Microsoft.EntityFrameworkCore.ChangeTracking)
Context 'DatabaseContext' started tracking 'Employee' entity with key '{Id: 4}'.
Full Log:
warn: 15/11/2024 12:36:41.870 CoreEventId.SensitiveDataLoggingEnabledWarning[10400] (Microsoft.EntityFrameworkCore.Infrastructure)
Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data; this mode should only be enabled during development.
dbug: 15/11/2024 12:36:41.933 CoreEventId.ContextInitialized[10403] (Microsoft.EntityFrameworkCore.Infrastructure)
Entity Framework Core 9.0.0 initialized 'DatabaseContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer:9.0.0' with options: EngineType=SqlServer SensitiveDataLoggingEnabled DetailedErrorsEnabled
dbug: 15/11/2024 12:36:41.940 RelationalEventId.ConnectionCreating[20005] (Microsoft.EntityFrameworkCore.Database.Connection)
Creating DbConnection.
dbug: 15/11/2024 12:36:41.970 RelationalEventId.ConnectionCreated[20006] (Microsoft.EntityFrameworkCore.Database.Connection)
Created DbConnection. (28ms).
dbug: 15/11/2024 12:36:41.971 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command)
Creating DbCommand for 'ExecuteNonQuery'.
dbug: 15/11/2024 12:36:41.975 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
Created DbCommand for 'ExecuteNonQuery' (35ms).
dbug: 15/11/2024 12:36:41.976 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command)
Initialized DbCommand for 'ExecuteNonQuery' (38ms).
dbug: 15/11/2024 12:36:41.978 RelationalEventId.ConnectionOpening[20000] (Microsoft.EntityFrameworkCore.Database.Connection)
Opening connection to database 'EF8_Issue_Testing' on server '.'.
dbug: 15/11/2024 12:36:42.153 RelationalEventId.ConnectionOpened[20001] (Microsoft.EntityFrameworkCore.Database.Connection)
Opened connection to database 'EF8_Issue_Testing' on server '.'.
dbug: 15/11/2024 12:36:42.156 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
DELETE FROM [Employee]
info: 15/11/2024 12:36:42.171 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (15ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
DELETE FROM [Employee]
dbug: 15/11/2024 12:36:42.172 RelationalEventId.ConnectionClosing[20002] (Microsoft.EntityFrameworkCore.Database.Connection)
Closing connection to database 'EF8_Issue_Testing' on server '.'.
dbug: 15/11/2024 12:36:42.176 RelationalEventId.ConnectionClosed[20003] (Microsoft.EntityFrameworkCore.Database.Connection)
Closed connection to database 'EF8_Issue_Testing' on server '.' (2ms).
dbug: 15/11/2024 12:36:42.176 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command)
Creating DbCommand for 'ExecuteNonQuery'.
dbug: 15/11/2024 12:36:42.177 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
Created DbCommand for 'ExecuteNonQuery' (0ms).
dbug: 15/11/2024 12:36:42.177 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command)
Initialized DbCommand for 'ExecuteNonQuery' (0ms).
dbug: 15/11/2024 12:36:42.177 RelationalEventId.ConnectionOpening[20000] (Microsoft.EntityFrameworkCore.Database.Connection)
Opening connection to database 'EF8_Issue_Testing' on server '.'.
dbug: 15/11/2024 12:36:42.177 RelationalEventId.ConnectionOpened[20001] (Microsoft.EntityFrameworkCore.Database.Connection)
Opened connection to database 'EF8_Issue_Testing' on server '.'.
dbug: 15/11/2024 12:36:42.177 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
DELETE FROM [HomePage]
info: 15/11/2024 12:36:42.180 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (3ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
DELETE FROM [HomePage]
dbug: 15/11/2024 12:36:42.180 RelationalEventId.ConnectionClosing[20002] (Microsoft.EntityFrameworkCore.Database.Connection)
Closing connection to database 'EF8_Issue_Testing' on server '.'.
dbug: 15/11/2024 12:36:42.180 RelationalEventId.ConnectionClosed[20003] (Microsoft.EntityFrameworkCore.Database.Connection)
Closed connection to database 'EF8_Issue_Testing' on server '.' (0ms).
dbug: 15/11/2024 12:36:42.181 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command)
Creating DbCommand for 'ExecuteNonQuery'.
dbug: 15/11/2024 12:36:42.181 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
Created DbCommand for 'ExecuteNonQuery' (0ms).
dbug: 15/11/2024 12:36:42.181 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command)
Initialized DbCommand for 'ExecuteNonQuery' (0ms).
dbug: 15/11/2024 12:36:42.181 RelationalEventId.ConnectionOpening[20000] (Microsoft.EntityFrameworkCore.Database.Connection)
Opening connection to database 'EF8_Issue_Testing' on server '.'.
dbug: 15/11/2024 12:36:42.181 RelationalEventId.ConnectionOpened[20001] (Microsoft.EntityFrameworkCore.Database.Connection)
Opened connection to database 'EF8_Issue_Testing' on server '.'.
dbug: 15/11/2024 12:36:42.181 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
DELETE FROM [Title]
info: 15/11/2024 12:36:42.183 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
DELETE FROM [Title]
dbug: 15/11/2024 12:36:42.183 RelationalEventId.ConnectionClosing[20002] (Microsoft.EntityFrameworkCore.Database.Connection)
Closing connection to database 'EF8_Issue_Testing' on server '.'.
dbug: 15/11/2024 12:36:42.183 RelationalEventId.ConnectionClosed[20003] (Microsoft.EntityFrameworkCore.Database.Connection)
Closed connection to database 'EF8_Issue_Testing' on server '.' (0ms).
dbug: 15/11/2024 12:36:42.184 RelationalEventId.ConnectionOpening[20000] (Microsoft.EntityFrameworkCore.Database.Connection)
Opening connection to database 'EF8_Issue_Testing' on server '.'.
dbug: 15/11/2024 12:36:42.184 RelationalEventId.ConnectionOpened[20001] (Microsoft.EntityFrameworkCore.Database.Connection)
Opened connection to database 'EF8_Issue_Testing' on server '.'.
dbug: 15/11/2024 12:36:42.185 RelationalEventId.TransactionStarting[20209] (Microsoft.EntityFrameworkCore.Database.Transaction)
Beginning transaction with isolation level 'Unspecified'.
dbug: 15/11/2024 12:36:42.188 RelationalEventId.TransactionStarted[20200] (Microsoft.EntityFrameworkCore.Database.Transaction)
Began transaction with isolation level 'ReadCommitted'.
dbug: 15/11/2024 12:36:42.189 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command)
Creating DbCommand for 'ExecuteNonQuery'.
dbug: 15/11/2024 12:36:42.189 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
Created DbCommand for 'ExecuteNonQuery' (0ms).
dbug: 15/11/2024 12:36:42.189 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command)
Initialized DbCommand for 'ExecuteNonQuery' (0ms).
dbug: 15/11/2024 12:36:42.189 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
SET IDENTITY_INSERT [HomePage] ON
info: 15/11/2024 12:36:42.190 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SET IDENTITY_INSERT [HomePage] ON
dbug: 15/11/2024 12:36:42.238 CoreEventId.StartedTracking[10806] (Microsoft.EntityFrameworkCore.ChangeTracking)
Context 'DatabaseContext' started tracking 'HomePage' entity with key '{Id: 1}'.
dbug: 15/11/2024 12:36:42.240 CoreEventId.StartedTracking[10806] (Microsoft.EntityFrameworkCore.ChangeTracking)
Context 'DatabaseContext' started tracking 'HomePage' entity with key '{Id: 2}'.
dbug: 15/11/2024 12:36:42.240 CoreEventId.StartedTracking[10806] (Microsoft.EntityFrameworkCore.ChangeTracking)
Context 'DatabaseContext' started tracking 'HomePage' entity with key '{Id: 4}'.
dbug: 15/11/2024 12:36:42.241 CoreEventId.SaveChangesStarting[10004] (Microsoft.EntityFrameworkCore.Update)
SaveChanges starting for 'DatabaseContext'.
dbug: 15/11/2024 12:36:42.242 CoreEventId.DetectChangesStarting[10800] (Microsoft.EntityFrameworkCore.ChangeTracking)
DetectChanges starting for 'DatabaseContext'.
dbug: 15/11/2024 12:36:42.250 CoreEventId.DetectChangesCompleted[10801] (Microsoft.EntityFrameworkCore.ChangeTracking)
DetectChanges completed for 'DatabaseContext'.
dbug: 15/11/2024 12:36:42.303 RelationalEventId.BatchReadyForExecution[20700] (Microsoft.EntityFrameworkCore.Update)
Executing 3 update commands as a batch.
dbug: 15/11/2024 12:36:42.314 RelationalEventId.CreatingTransactionSavepoint[20212] (Microsoft.EntityFrameworkCore.Database.Transaction)
Creating transaction savepoint.
dbug: 15/11/2024 12:36:42.315 RelationalEventId.CreatedTransactionSavepoint[20213] (Microsoft.EntityFrameworkCore.Database.Transaction)
Created transaction savepoint.
dbug: 15/11/2024 12:36:42.316 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command)
Creating DbCommand for 'ExecuteReader'.
dbug: 15/11/2024 12:36:42.316 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
Created DbCommand for 'ExecuteReader' (0ms).
dbug: 15/11/2024 12:36:42.319 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command)
Initialized DbCommand for 'ExecuteReader' (3ms).
dbug: 15/11/2024 12:36:42.321 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
Executing DbCommand [Parameters=[@p0='1', @p1='1' (Nullable = false) (Size = 16), @p2='1', @p3='True', @p4='False', @p5='1' (Nullable = false) (Size = 150), @p6='False', @p7='1', @p8='2', @p9='2' (Nullable = false) (Size = 16), @p10='2', @p11='True', @p12='True', @p13='2' (Nullable = false) (Size = 150), @p14='False', @p15='2', @p16='4', @p17='3' (Nullable = false) (Size = 16), @p18='4', @p19='True', @p20='False', @p21='3' (Nullable = false) (Size = 150), @p22='False', @p23='3'], CommandType='Text', CommandTimeout='30']
SET IMPLICIT_TRANSACTIONS OFF;
SET NOCOUNT ON;
INSERT INTO [HomePage] ([Id], [Code], [DisplayOrder], [IsActive], [IsDefault], [Name], [OrganisationAdminOnly], [RedirectPage])
VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7),
(@p8, @p9, @p10, @p11, @p12, @p13, @p14, @p15),
(@p16, @p17, @p18, @p19, @p20, @p21, @p22, @p23);
info: 15/11/2024 12:36:42.343 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (23ms) [Parameters=[@p0='1', @p1='1' (Nullable = false) (Size = 16), @p2='1', @p3='True', @p4='False', @p5='1' (Nullable = false) (Size = 150), @p6='False', @p7='1', @p8='2', @p9='2' (Nullable = false) (Size = 16), @p10='2', @p11='True', @p12='True', @p13='2' (Nullable = false) (Size = 150), @p14='False', @p15='2', @p16='4', @p17='3' (Nullable = false) (Size = 16), @p18='4', @p19='True', @p20='False', @p21='3' (Nullable = false) (Size = 150), @p22='False', @p23='3'], CommandType='Text', CommandTimeout='30']
SET IMPLICIT_TRANSACTIONS OFF;
SET NOCOUNT ON;
INSERT INTO [HomePage] ([Id], [Code], [DisplayOrder], [IsActive], [IsDefault], [Name], [OrganisationAdminOnly], [RedirectPage])
VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7),
(@p8, @p9, @p10, @p11, @p12, @p13, @p14, @p15),
(@p16, @p17, @p18, @p19, @p20, @p21, @p22, @p23);
dbug: 15/11/2024 12:36:42.346 RelationalEventId.DataReaderClosing[20301] (Microsoft.EntityFrameworkCore.Database.Command)
Closing data reader to 'EF8_Issue_Testing' on server '.'.
dbug: 15/11/2024 12:36:42.349 RelationalEventId.DataReaderDisposing[20300] (Microsoft.EntityFrameworkCore.Database.Command)
A data reader for 'EF8_Issue_Testing' on server '.' is being disposed after spending 3ms reading results.
dbug: 15/11/2024 12:36:42.354 CoreEventId.StateChanged[10807] (Microsoft.EntityFrameworkCore.ChangeTracking)
The 'HomePage' entity with key '{Id: 1}' tracked by 'DatabaseContext' changed state from 'Added' to 'Unchanged'.
dbug: 15/11/2024 12:36:42.354 CoreEventId.StateChanged[10807] (Microsoft.EntityFrameworkCore.ChangeTracking)
The 'HomePage' entity with key '{Id: 2}' tracked by 'DatabaseContext' changed state from 'Added' to 'Unchanged'.
dbug: 15/11/2024 12:36:42.354 CoreEventId.StateChanged[10807] (Microsoft.EntityFrameworkCore.ChangeTracking)
The 'HomePage' entity with key '{Id: 4}' tracked by 'DatabaseContext' changed state from 'Added' to 'Unchanged'.
dbug: 15/11/2024 12:36:42.355 CoreEventId.SaveChangesCompleted[10005] (Microsoft.EntityFrameworkCore.Update)
SaveChanges completed for 'DatabaseContext' with 3 entities written to the database.
dbug: 15/11/2024 12:36:42.366 CoreEventId.QueryCompilationStarting[10111] (Microsoft.EntityFrameworkCore.Query)
Compiling query expression:
'DbSet<HomePage>()'
dbug: 15/11/2024 12:36:42.450 CoreEventId.QueryExecutionPlanned[10107] (Microsoft.EntityFrameworkCore.Query)
Generated query execution expression:
'queryContext => SingleQueryingEnumerable.Create<HomePage>(
relationalQueryContext: (RelationalQueryContext)queryContext,
relationalCommandResolver: parameters => [LIFTABLE Constant: RelationalCommandCache.QueryExpression(
Projection Mapping:
EmptyProjectionMember -> Dictionary<IProperty, int> { [Property: HomePage.Id (int?) Required PK AfterSave:Throw ValueGenerated.OnAdd, 0], [Property: HomePage.Code (string) Required MaxLength(16), 1], [Property: HomePage.DisplayOrder (int) Required, 2], [Property: HomePage.IsActive (bool) Required, 3], [Property: HomePage.IsDefault (bool) Required, 4], [Property: HomePage.Name (string) Required MaxLength(150), 5], [Property: HomePage.OrganisationAdminOnly (bool) Required, 6], [Property: HomePage.RedirectPage (int) Required, 7] }
SELECT h.Id, h.Code, h.DisplayOrder, h.IsActive, h.IsDefault, h.Name, h.OrganisationAdminOnly, h.RedirectPage
FROM HomePage AS h) | Resolver: c => new RelationalCommandCache(
c.Dependencies.MemoryCache,
c.RelationalDependencies.QuerySqlGeneratorFactory,
c.RelationalDependencies.RelationalParameterBasedSqlProcessorFactory,
Projection Mapping:
EmptyProjectionMember -> Dictionary<IProperty, int> { [Property: HomePage.Id (int?) Required PK AfterSave:Throw ValueGenerated.OnAdd, 0], [Property: HomePage.Code (string) Required MaxLength(16), 1], [Property: HomePage.DisplayOrder (int) Required, 2], [Property: HomePage.IsActive (bool) Required, 3], [Property: HomePage.IsDefault (bool) Required, 4], [Property: HomePage.Name (string) Required MaxLength(150), 5], [Property: HomePage.OrganisationAdminOnly (bool) Required, 6], [Property: HomePage.RedirectPage (int) Required, 7] }
SELECT h.Id, h.Code, h.DisplayOrder, h.IsActive, h.IsDefault, h.Name, h.OrganisationAdminOnly, h.RedirectPage
FROM HomePage AS h,
False,
new HashSet<string>(
new string[]{ },
StringComparer.Ordinal
)
)].GetRelationalCommandTemplate(parameters),
readerColumns: null,
shaper: (queryContext, dataReader, resultContext, resultCoordinator) =>
{
HomePage entity;
entity =
{
MaterializationContext materializationContext1;
IEntityType entityType1;
HomePage instance1;
InternalEntityEntry entry1;
bool hasNullKey1;
materializationContext1 = new MaterializationContext(
[LIFTABLE Constant: ValueBuffer | Resolver: _ => (object)ValueBuffer.Empty],
queryContext.Context
);
instance1 = default(HomePage);
entry1 = queryContext.TryGetEntry(
key: [LIFTABLE Constant: Key: HomePage.Id PK | Resolver: c => c.Dependencies.Model.FindEntityType("EF_Core_8_Issue.DbSetEntities.HomePage").FindPrimaryKey()],
keyValues: new object[]{ try { (object)dataReader.GetInt32(0) } catch (Exception) { ... } },
throwOnNullKey: True,
hasNullKey: hasNullKey1);
!(hasNullKey1) ? entry1 != default(InternalEntityEntry) ?
{
entityType1 = entry1.EntityType;
return instance1 = (HomePage)entry1.Entity;
} :
{
ISnapshot shadowSnapshot1;
shadowSnapshot1 = [LIFTABLE Constant: Snapshot | Resolver: _ => Snapshot.Empty];
entityType1 = [LIFTABLE Constant: EntityType: HomePage | Resolver: namelessParameter{0} => namelessParameter{0}.Dependencies.Model.FindEntityType("EF_Core_8_Issue.DbSetEntities.HomePage")];
instance1 = switch (entityType1)
{
case [LIFTABLE Constant: EntityType: HomePage | Resolver: namelessParameter{1} => namelessParameter{1}.Dependencies.Model.FindEntityType("EF_Core_8_Issue.DbSetEntities.HomePage")]:
{
return
{
HomePage instance;
instance = new HomePage();
instance.<Id>k__BackingField = try { (int?)dataReader.GetInt32(0) } catch (Exception) { ... } ;
instance.<Code>k__BackingField = try { dataReader.GetString(1) } catch (Exception) { ... } ;
instance.<DisplayOrder>k__BackingField = try { dataReader.GetInt32(2) } catch (Exception) { ... } ;
instance.<IsActive>k__BackingField = try { dataReader.GetBoolean(3) } catch (Exception) { ... } ;
instance.<IsDefault>k__BackingField = try { dataReader.GetBoolean(4) } catch (Exception) { ... } ;
instance.<Name>k__BackingField = try { dataReader.GetString(5) } catch (Exception) { ... } ;
instance.<OrganisationAdminOnly>k__BackingField = try { dataReader.GetBoolean(6) } catch (Exception) { ... } ;
instance.<RedirectPage>k__BackingField = try { dataReader.GetInt32(7) } catch (Exception) { ... } ;
(instance is IInjectableService) ? ((IInjectableService)instance).Injected(
context: materializationContext1.Context,
entity: instance,
queryTrackingBehavior: TrackAll,
structuralType: [LIFTABLE Constant: EntityType: HomePage | Resolver: namelessParameter{2} => namelessParameter{2}.Dependencies.Model.FindEntityType("EF_Core_8_Issue.DbSetEntities.HomePage")]) : default(void);
return instance;
}}
default:
default(HomePage)
}
;
entry1 = entityType1 == default(IEntityType) ? default(InternalEntityEntry) : queryContext.StartTracking(
entityType: entityType1,
entity: instance1,
snapshot: shadowSnapshot1);
return instance1;
} : default(void);
return instance1;
};
return entity;
},
contextType: EF_Core_8_Issue.DatabaseContext,
standAloneStateManager: False,
detailedErrorsEnabled: True,
threadSafetyChecksEnabled: True)'
dbug: 15/11/2024 12:36:42.468 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command)
Creating DbCommand for 'ExecuteReader'.
dbug: 15/11/2024 12:36:42.468 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
Created DbCommand for 'ExecuteReader' (0ms).
dbug: 15/11/2024 12:36:42.468 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command)
Initialized DbCommand for 'ExecuteReader' (0ms).
dbug: 15/11/2024 12:36:42.468 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [h].[Id], [h].[Code], [h].[DisplayOrder], [h].[IsActive], [h].[IsDefault], [h].[Name], [h].[OrganisationAdminOnly], [h].[RedirectPage]
FROM [HomePage] AS [h]
info: 15/11/2024 12:36:42.471 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (3ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [h].[Id], [h].[Code], [h].[DisplayOrder], [h].[IsActive], [h].[IsDefault], [h].[Name], [h].[OrganisationAdminOnly], [h].[RedirectPage]
FROM [HomePage] AS [h]
dbug: 15/11/2024 12:36:42.475 RelationalEventId.DataReaderClosing[20301] (Microsoft.EntityFrameworkCore.Database.Command)
Closing data reader to 'EF8_Issue_Testing' on server '.'.
dbug: 15/11/2024 12:36:42.478 RelationalEventId.DataReaderDisposing[20300] (Microsoft.EntityFrameworkCore.Database.Command)
A data reader for 'EF8_Issue_Testing' on server '.' is being disposed after spending 6ms reading results.
dbug: 15/11/2024 12:36:42.478 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command)
Creating DbCommand for 'ExecuteNonQuery'.
dbug: 15/11/2024 12:36:42.480 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
Created DbCommand for 'ExecuteNonQuery' (1ms).
dbug: 15/11/2024 12:36:42.480 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command)
Initialized DbCommand for 'ExecuteNonQuery' (1ms).
dbug: 15/11/2024 12:36:42.480 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
SET IDENTITY_INSERT [HomePage] OFF
info: 15/11/2024 12:36:42.480 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SET IDENTITY_INSERT [HomePage] OFF
dbug: 15/11/2024 12:36:42.481 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command)
Creating DbCommand for 'ExecuteNonQuery'.
dbug: 15/11/2024 12:36:42.481 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
Created DbCommand for 'ExecuteNonQuery' (0ms).
dbug: 15/11/2024 12:36:42.481 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command)
Initialized DbCommand for 'ExecuteNonQuery' (0ms).
dbug: 15/11/2024 12:36:42.481 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
SET IDENTITY_INSERT [Title] ON
info: 15/11/2024 12:36:42.482 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SET IDENTITY_INSERT [Title] ON
dbug: 15/11/2024 12:36:42.489 CoreEventId.StartedTracking[10806] (Microsoft.EntityFrameworkCore.ChangeTracking)
Context 'DatabaseContext' started tracking 'Title' entity with key '{Id: 1}'.
dbug: 15/11/2024 12:36:42.491 CoreEventId.StartedTracking[10806] (Microsoft.EntityFrameworkCore.ChangeTracking)
Context 'DatabaseContext' started tracking 'Title' entity with key '{Id: 2}'.
dbug: 15/11/2024 12:36:42.492 CoreEventId.SaveChangesStarting[10004] (Microsoft.EntityFrameworkCore.Update)
SaveChanges starting for 'DatabaseContext'.
dbug: 15/11/2024 12:36:42.492 CoreEventId.DetectChangesStarting[10800] (Microsoft.EntityFrameworkCore.ChangeTracking)
DetectChanges starting for 'DatabaseContext'.
dbug: 15/11/2024 12:36:42.494 CoreEventId.DetectChangesCompleted[10801] (Microsoft.EntityFrameworkCore.ChangeTracking)
DetectChanges completed for 'DatabaseContext'.
dbug: 15/11/2024 12:36:42.495 RelationalEventId.BatchReadyForExecution[20700] (Microsoft.EntityFrameworkCore.Update)
Executing 2 update commands as a batch.
dbug: 15/11/2024 12:36:42.496 RelationalEventId.CreatingTransactionSavepoint[20212] (Microsoft.EntityFrameworkCore.Database.Transaction)
Creating transaction savepoint.
dbug: 15/11/2024 12:36:42.496 RelationalEventId.CreatedTransactionSavepoint[20213] (Microsoft.EntityFrameworkCore.Database.Transaction)
Created transaction savepoint.
dbug: 15/11/2024 12:36:42.496 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command)
Creating DbCommand for 'ExecuteReader'.
dbug: 15/11/2024 12:36:42.496 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
Created DbCommand for 'ExecuteReader' (0ms).
dbug: 15/11/2024 12:36:42.496 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command)
Initialized DbCommand for 'ExecuteReader' (0ms).
dbug: 15/11/2024 12:36:42.497 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
Executing DbCommand [Parameters=[@p0='1', @p1='MR' (Nullable = false) (Size = 16), @p2='0', @p3='True', @p4='True', @p5='Mr' (Nullable = false) (Size = 150), @p6='2', @p7='MRS' (Nullable = false) (Size = 16), @p8='1', @p9='True', @p10='False', @p11='Mrs' (Nullable = false) (Size = 150)], CommandType='Text', CommandTimeout='30']
SET IMPLICIT_TRANSACTIONS OFF;
SET NOCOUNT ON;
INSERT INTO [Title] ([Id], [Code], [DisplayOrder], [IsActive], [IsDefault], [Name])
VALUES (@p0, @p1, @p2, @p3, @p4, @p5),
(@p6, @p7, @p8, @p9, @p10, @p11);
info: 15/11/2024 12:36:42.499 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (2ms) [Parameters=[@p0='1', @p1='MR' (Nullable = false) (Size = 16), @p2='0', @p3='True', @p4='True', @p5='Mr' (Nullable = false) (Size = 150), @p6='2', @p7='MRS' (Nullable = false) (Size = 16), @p8='1', @p9='True', @p10='False', @p11='Mrs' (Nullable = false) (Size = 150)], CommandType='Text', CommandTimeout='30']
SET IMPLICIT_TRANSACTIONS OFF;
SET NOCOUNT ON;
INSERT INTO [Title] ([Id], [Code], [DisplayOrder], [IsActive], [IsDefault], [Name])
VALUES (@p0, @p1, @p2, @p3, @p4, @p5),
(@p6, @p7, @p8, @p9, @p10, @p11);
dbug: 15/11/2024 12:36:42.499 RelationalEventId.DataReaderClosing[20301] (Microsoft.EntityFrameworkCore.Database.Command)
Closing data reader to 'EF8_Issue_Testing' on server '.'.
dbug: 15/11/2024 12:36:42.500 RelationalEventId.DataReaderDisposing[20300] (Microsoft.EntityFrameworkCore.Database.Command)
A data reader for 'EF8_Issue_Testing' on server '.' is being disposed after spending 0ms reading results.
dbug: 15/11/2024 12:36:42.500 CoreEventId.StateChanged[10807] (Microsoft.EntityFrameworkCore.ChangeTracking)
The 'Title' entity with key '{Id: 2}' tracked by 'DatabaseContext' changed state from 'Added' to 'Unchanged'.
dbug: 15/11/2024 12:36:42.500 CoreEventId.StateChanged[10807] (Microsoft.EntityFrameworkCore.ChangeTracking)
The 'Title' entity with key '{Id: 1}' tracked by 'DatabaseContext' changed state from 'Added' to 'Unchanged'.
dbug: 15/11/2024 12:36:42.500 CoreEventId.SaveChangesCompleted[10005] (Microsoft.EntityFrameworkCore.Update)
SaveChanges completed for 'DatabaseContext' with 2 entities written to the database.
dbug: 15/11/2024 12:36:42.501 CoreEventId.QueryCompilationStarting[10111] (Microsoft.EntityFrameworkCore.Query)
Compiling query expression:
'DbSet<Title>()'
dbug: 15/11/2024 12:36:42.503 CoreEventId.QueryExecutionPlanned[10107] (Microsoft.EntityFrameworkCore.Query)
Generated query execution expression:
'queryContext => SingleQueryingEnumerable.Create<Title>(
relationalQueryContext: (RelationalQueryContext)queryContext,
relationalCommandResolver: parameters => [LIFTABLE Constant: RelationalCommandCache.QueryExpression(
Projection Mapping:
EmptyProjectionMember -> Dictionary<IProperty, int> { [Property: Title.Id (int?) Required PK AfterSave:Throw ValueGenerated.OnAdd, 0], [Property: Title.Code (string) Required MaxLength(16), 1], [Property: Title.DisplayOrder (int) Required, 2], [Property: Title.IsActive (bool) Required, 3], [Property: Title.IsDefault (bool) Required, 4], [Property: Title.Name (string) Required MaxLength(150), 5] }
SELECT t.Id, t.Code, t.DisplayOrder, t.IsActive, t.IsDefault, t.Name
FROM Title AS t) | Resolver: c => new RelationalCommandCache(
c.Dependencies.MemoryCache,
c.RelationalDependencies.QuerySqlGeneratorFactory,
c.RelationalDependencies.RelationalParameterBasedSqlProcessorFactory,
Projection Mapping:
EmptyProjectionMember -> Dictionary<IProperty, int> { [Property: Title.Id (int?) Required PK AfterSave:Throw ValueGenerated.OnAdd, 0], [Property: Title.Code (string) Required MaxLength(16), 1], [Property: Title.DisplayOrder (int) Required, 2], [Property: Title.IsActive (bool) Required, 3], [Property: Title.IsDefault (bool) Required, 4], [Property: Title.Name (string) Required MaxLength(150), 5] }
SELECT t.Id, t.Code, t.DisplayOrder, t.IsActive, t.IsDefault, t.Name
FROM Title AS t,
False,
new HashSet<string>(
new string[]{ },
StringComparer.Ordinal
)
)].GetRelationalCommandTemplate(parameters),
readerColumns: null,
shaper: (queryContext, dataReader, resultContext, resultCoordinator) =>
{
Title entity;
entity =
{
MaterializationContext materializationContext1;
IEntityType entityType1;
Title instance1;
InternalEntityEntry entry1;
bool hasNullKey1;
materializationContext1 = new MaterializationContext(
[LIFTABLE Constant: ValueBuffer | Resolver: _ => (object)ValueBuffer.Empty],
queryContext.Context
);
instance1 = default(Title);
entry1 = queryContext.TryGetEntry(
key: [LIFTABLE Constant: Key: Title.Id PK | Resolver: c => c.Dependencies.Model.FindEntityType("EF_Core_8_Issue.DbSetEntities.Title").FindPrimaryKey()],
keyValues: new object[]{ try { (object)dataReader.GetInt32(0) } catch (Exception) { ... } },
throwOnNullKey: True,
hasNullKey: hasNullKey1);
!(hasNullKey1) ? entry1 != default(InternalEntityEntry) ?
{
entityType1 = entry1.EntityType;
return instance1 = (Title)entry1.Entity;
} :
{
ISnapshot shadowSnapshot1;
shadowSnapshot1 = [LIFTABLE Constant: Snapshot | Resolver: _ => Snapshot.Empty];
entityType1 = [LIFTABLE Constant: EntityType: Title | Resolver: namelessParameter{0} => namelessParameter{0}.Dependencies.Model.FindEntityType("EF_Core_8_Issue.DbSetEntities.Title")];
instance1 = switch (entityType1)
{
case [LIFTABLE Constant: EntityType: Title | Resolver: namelessParameter{1} => namelessParameter{1}.Dependencies.Model.FindEntityType("EF_Core_8_Issue.DbSetEntities.Title")]:
{
return
{
Title instance;
instance = new Title();
instance.<Id>k__BackingField = try { (int?)dataReader.GetInt32(0) } catch (Exception) { ... } ;
instance.<Code>k__BackingField = try { dataReader.GetString(1) } catch (Exception) { ... } ;
instance.<DisplayOrder>k__BackingField = try { dataReader.GetInt32(2) } catch (Exception) { ... } ;
instance.<IsActive>k__BackingField = try { dataReader.GetBoolean(3) } catch (Exception) { ... } ;
instance.<IsDefault>k__BackingField = try { dataReader.GetBoolean(4) } catch (Exception) { ... } ;
instance.<Name>k__BackingField = try { dataReader.GetString(5) } catch (Exception) { ... } ;
(instance is IInjectableService) ? ((IInjectableService)instance).Injected(
context: materializationContext1.Context,
entity: instance,
queryTrackingBehavior: TrackAll,
structuralType: [LIFTABLE Constant: EntityType: Title | Resolver: namelessParameter{2} => namelessParameter{2}.Dependencies.Model.FindEntityType("EF_Core_8_Issue.DbSetEntities.Title")]) : default(void);
return instance;
}}
default:
default(Title)
}
;
entry1 = entityType1 == default(IEntityType) ? default(InternalEntityEntry) : queryContext.StartTracking(
entityType: entityType1,
entity: instance1,
snapshot: shadowSnapshot1);
return instance1;
} : default(void);
return instance1;
};
return entity;
},
contextType: EF_Core_8_Issue.DatabaseContext,
standAloneStateManager: False,
detailedErrorsEnabled: True,
threadSafetyChecksEnabled: True)'
dbug: 15/11/2024 12:36:42.513 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command)
Creating DbCommand for 'ExecuteReader'.
dbug: 15/11/2024 12:36:42.513 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
Created DbCommand for 'ExecuteReader' (0ms).
dbug: 15/11/2024 12:36:42.514 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command)
Initialized DbCommand for 'ExecuteReader' (0ms).
dbug: 15/11/2024 12:36:42.514 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [t].[Id], [t].[Code], [t].[DisplayOrder], [t].[IsActive], [t].[IsDefault], [t].[Name]
FROM [Title] AS [t]
info: 15/11/2024 12:36:42.515 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [t].[Id], [t].[Code], [t].[DisplayOrder], [t].[IsActive], [t].[IsDefault], [t].[Name]
FROM [Title] AS [t]
dbug: 15/11/2024 12:36:42.515 RelationalEventId.DataReaderClosing[20301] (Microsoft.EntityFrameworkCore.Database.Command)
Closing data reader to 'EF8_Issue_Testing' on server '.'.
dbug: 15/11/2024 12:36:42.516 RelationalEventId.DataReaderDisposing[20300] (Microsoft.EntityFrameworkCore.Database.Command)
A data reader for 'EF8_Issue_Testing' on server '.' is being disposed after spending 0ms reading results.
dbug: 15/11/2024 12:36:42.516 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command)
Creating DbCommand for 'ExecuteNonQuery'.
dbug: 15/11/2024 12:36:42.516 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
Created DbCommand for 'ExecuteNonQuery' (0ms).
dbug: 15/11/2024 12:36:42.516 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command)
Initialized DbCommand for 'ExecuteNonQuery' (0ms).
dbug: 15/11/2024 12:36:42.516 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
SET IDENTITY_INSERT [Title] OFF
info: 15/11/2024 12:36:42.517 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SET IDENTITY_INSERT [Title] OFF
dbug: 15/11/2024 12:36:42.517 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command)
Creating DbCommand for 'ExecuteNonQuery'.
dbug: 15/11/2024 12:36:42.517 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
Created DbCommand for 'ExecuteNonQuery' (0ms).
dbug: 15/11/2024 12:36:42.517 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command)
Initialized DbCommand for 'ExecuteNonQuery' (0ms).
dbug: 15/11/2024 12:36:42.518 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
SET IDENTITY_INSERT [Employee] ON
info: 15/11/2024 12:36:42.518 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SET IDENTITY_INSERT [Employee] ON
dbug: 15/11/2024 12:36:42.528 CoreEventId.ReferenceChangeDetected[10805] (Microsoft.EntityFrameworkCore.ChangeTracking)
The navigation 'Employee.DefaultHomePage' for entity with key '{Id: 1}' was detected as changed.
dbug: 15/11/2024 12:36:42.532 CoreEventId.ReferenceChangeDetected[10805] (Microsoft.EntityFrameworkCore.ChangeTracking)
The navigation 'Employee.Title' for entity with key '{Id: 1}' was detected as changed.
dbug: 15/11/2024 12:36:42.532 CoreEventId.StartedTracking[10806] (Microsoft.EntityFrameworkCore.ChangeTracking)
Context 'DatabaseContext' started tracking 'Employee' entity with key '{Id: 1}'.
dbug: 15/11/2024 12:36:42.533 CoreEventId.ReferenceChangeDetected[10805] (Microsoft.EntityFrameworkCore.ChangeTracking)
The navigation 'Employee.DefaultHomePage' for entity with key '{Id: 2}' was detected as changed.
dbug: 15/11/2024 12:36:42.536 CoreEventId.CascadeDeleteOrphan[10003] (Microsoft.EntityFrameworkCore.Update)
An entity of type 'Employee' with key '{Id: 1}' changed to 'Detached' state due to severed required relationship to its parent entity of type 'HomePage'.
dbug: 15/11/2024 12:36:42.539 CoreEventId.StateChanged[10807] (Microsoft.EntityFrameworkCore.ChangeTracking)
The 'Employee' entity with key '{Id: 1}' tracked by 'DatabaseContext' changed state from 'Added' to 'Detached'.
dbug: 15/11/2024 12:36:42.540 CoreEventId.ReferenceChangeDetected[10805] (Microsoft.EntityFrameworkCore.ChangeTracking)
The navigation 'Employee.Title' for entity with key '{Id: 2}' was detected as changed.
dbug: 15/11/2024 12:36:42.540 CoreEventId.StartedTracking[10806] (Microsoft.EntityFrameworkCore.ChangeTracking)
Context 'DatabaseContext' started tracking 'Employee' entity with key '{Id: 2}'.
dbug: 15/11/2024 12:36:42.540 CoreEventId.ReferenceChangeDetected[10805] (Microsoft.EntityFrameworkCore.ChangeTracking)
The navigation 'Employee.DefaultHomePage' for entity with key '{Id: 3}' was detected as changed.
dbug: 15/11/2024 12:36:42.541 CoreEventId.ReferenceChangeDetected[10805] (Microsoft.EntityFrameworkCore.ChangeTracking)
The navigation 'Employee.Title' for entity with key '{Id: 3}' was detected as changed.
dbug: 15/11/2024 12:36:42.541 CoreEventId.StartedTracking[10806] (Microsoft.EntityFrameworkCore.ChangeTracking)
Context 'DatabaseContext' started tracking 'Employee' entity with key '{Id: 3}'.
dbug: 15/11/2024 12:36:42.541 CoreEventId.ReferenceChangeDetected[10805] (Microsoft.EntityFrameworkCore.ChangeTracking)
The navigation 'Employee.DefaultHomePage' for entity with key '{Id: 4}' was detected as changed.
dbug: 15/11/2024 12:36:42.542 CoreEventId.ReferenceChangeDetected[10805] (Microsoft.EntityFrameworkCore.ChangeTracking)
The navigation 'Employee.Title' for entity with key '{Id: 4}' was detected as changed.
dbug: 15/11/2024 12:36:42.545 CoreEventId.ForeignKeyChangeDetected[10803] (Microsoft.EntityFrameworkCore.ChangeTracking)
The foreign key property 'Employee.TitleId' was detected as changed from '2' to '(null)' for entity with key '{Id: 3}'.
dbug: 15/11/2024 12:36:42.547 CoreEventId.ReferenceChangeDetected[10805] (Microsoft.EntityFrameworkCore.ChangeTracking)
The navigation 'Employee.Title' for entity with key '{Id: 3}' was detected as changed.
dbug: 15/11/2024 12:36:42.547 CoreEventId.StartedTracking[10806] (Microsoft.EntityFrameworkCore.ChangeTracking)
Context 'DatabaseContext' started tracking 'Employee' entity with key '{Id: 4}'.
dbug: 15/11/2024 12:36:42.547 CoreEventId.SaveChangesStarting[10004] (Microsoft.EntityFrameworkCore.Update)
SaveChanges starting for 'DatabaseContext'.
dbug: 15/11/2024 12:36:42.547 CoreEventId.DetectChangesStarting[10800] (Microsoft.EntityFrameworkCore.ChangeTracking)
DetectChanges starting for 'DatabaseContext'.
dbug: 15/11/2024 12:36:42.549 CoreEventId.DetectChangesCompleted[10801] (Microsoft.EntityFrameworkCore.ChangeTracking)
DetectChanges completed for 'DatabaseContext'.
dbug: 15/11/2024 12:36:42.551 RelationalEventId.BatchReadyForExecution[20700] (Microsoft.EntityFrameworkCore.Update)
Executing 3 update commands as a batch.
dbug: 15/11/2024 12:36:42.554 RelationalEventId.CreatingTransactionSavepoint[20212] (Microsoft.EntityFrameworkCore.Database.Transaction)
Creating transaction savepoint.
dbug: 15/11/2024 12:36:42.554 RelationalEventId.CreatedTransactionSavepoint[20213] (Microsoft.EntityFrameworkCore.Database.Transaction)
Created transaction savepoint.
dbug: 15/11/2024 12:36:42.554 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command)
Creating DbCommand for 'ExecuteReader'.
dbug: 15/11/2024 12:36:42.555 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
Created DbCommand for 'ExecuteReader' (0ms).
dbug: 15/11/2024 12:36:42.555 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command)
Initialized DbCommand for 'ExecuteReader' (0ms).
dbug: 15/11/2024 12:36:42.555 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
Executing DbCommand [Parameters=[@p0='2', @p1='1', @p2='Lawrence' (Size = 32), @p3='Pilkington' (Size = 32), @p4='1' (Nullable = true), @p5='3', @p6='1', @p7='Sally' (Size = 32), @p8='Taylor' (Size = 32), @p9=NULL (DbType = Int32), @p10='4', @p11='1', @p12='Rachel' (Size = 32), @p13='Wilkes' (Size = 32), @p14='2' (Nullable = true)], CommandType='Text', CommandTimeout='30']
SET IMPLICIT_TRANSACTIONS OFF;
SET NOCOUNT ON;
INSERT INTO [Employee] ([Id], [DefaultHomePageId], [FirstName], [LastName], [TitleId])
VALUES (@p0, @p1, @p2, @p3, @p4),
(@p5, @p6, @p7, @p8, @p9),
(@p10, @p11, @p12, @p13, @p14);
info: 15/11/2024 12:36:42.559 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (4ms) [Parameters=[@p0='2', @p1='1', @p2='Lawrence' (Size = 32), @p3='Pilkington' (Size = 32), @p4='1' (Nullable = true), @p5='3', @p6='1', @p7='Sally' (Size = 32), @p8='Taylor' (Size = 32), @p9=NULL (DbType = Int32), @p10='4', @p11='1', @p12='Rachel' (Size = 32), @p13='Wilkes' (Size = 32), @p14='2' (Nullable = true)], CommandType='Text', CommandTimeout='30']
SET IMPLICIT_TRANSACTIONS OFF;
SET NOCOUNT ON;
INSERT INTO [Employee] ([Id], [DefaultHomePageId], [FirstName], [LastName], [TitleId])
VALUES (@p0, @p1, @p2, @p3, @p4),
(@p5, @p6, @p7, @p8, @p9),
(@p10, @p11, @p12, @p13, @p14);
dbug: 15/11/2024 12:36:42.559 RelationalEventId.DataReaderClosing[20301] (Microsoft.EntityFrameworkCore.Database.Command)
Closing data reader to 'EF8_Issue_Testing' on server '.'.
dbug: 15/11/2024 12:36:42.560 RelationalEventId.DataReaderDisposing[20300] (Microsoft.EntityFrameworkCore.Database.Command)
A data reader for 'EF8_Issue_Testing' on server '.' is being disposed after spending 0ms reading results.
dbug: 15/11/2024 12:36:42.560 CoreEventId.StateChanged[10807] (Microsoft.EntityFrameworkCore.ChangeTracking)
The 'Employee' entity with key '{Id: 4}' tracked by 'DatabaseContext' changed state from 'Added' to 'Unchanged'.
dbug: 15/11/2024 12:36:42.560 CoreEventId.StateChanged[10807] (Microsoft.EntityFrameworkCore.ChangeTracking)
The 'Employee' entity with key '{Id: 2}' tracked by 'DatabaseContext' changed state from 'Added' to 'Unchanged'.
dbug: 15/11/2024 12:36:42.560 CoreEventId.StateChanged[10807] (Microsoft.EntityFrameworkCore.ChangeTracking)
The 'Employee' entity with key '{Id: 3}' tracked by 'DatabaseContext' changed state from 'Added' to 'Unchanged'.
dbug: 15/11/2024 12:36:42.560 CoreEventId.SaveChangesCompleted[10005] (Microsoft.EntityFrameworkCore.Update)
SaveChanges completed for 'DatabaseContext' with 3 entities written to the database.
dbug: 15/11/2024 12:36:42.561 CoreEventId.QueryCompilationStarting[10111] (Microsoft.EntityFrameworkCore.Query)
Compiling query expression:
'DbSet<Employee>()'
dbug: 15/11/2024 12:36:42.576 CoreEventId.NavigationBaseIncluded[10112] (Microsoft.EntityFrameworkCore.Query)
Including navigation: 'Employee.DefaultHomePage'.
dbug: 15/11/2024 12:36:42.577 CoreEventId.NavigationBaseIncluded[10112] (Microsoft.EntityFrameworkCore.Query)
Including navigation: 'Employee.Title'.
dbug: 15/11/2024 12:36:42.609 CoreEventId.QueryExecutionPlanned[10107] (Microsoft.EntityFrameworkCore.Query)
Generated query execution expression:
'queryContext => SingleQueryingEnumerable.Create<Employee>(
relationalQueryContext: (RelationalQueryContext)queryContext,
relationalCommandResolver: parameters => [LIFTABLE Constant: RelationalCommandCache.QueryExpression(
Client Projections:
0 -> Dictionary<IProperty, int> { [Property: Employee.Id (int?) Required PK AfterSave:Throw ValueGenerated.OnAdd, 0], [Property: Employee.DefaultHomePageId (int) Required FK Index, 1], [Property: Employee.FirstName (string) MaxLength(32), 2], [Property: Employee.LastName (string) MaxLength(32), 3], [Property: Employee.TitleId (int?) FK Index, 4] }
1 -> Dictionary<IProperty, int> { [Property: HomePage.Id (int?) Required PK AfterSave:Throw ValueGenerated.OnAdd, 5], [Property: HomePage.Code (string) Required MaxLength(16), 6], [Property: HomePage.DisplayOrder (int) Required, 7], [Property: HomePage.IsActive (bool) Required, 8], [Property: HomePage.IsDefault (bool) Required, 9], [Property: HomePage.Name (string) Required MaxLength(150), 10], [Property: HomePage.OrganisationAdminOnly (bool) Required, 11], [Property: HomePage.RedirectPage (int) Required, 12] }
2 -> Dictionary<IProperty, int> { [Property: Title.Id (int?) Required PK AfterSave:Throw ValueGenerated.OnAdd, 13], [Property: Title.Code (string) Required MaxLength(16), 14], [Property: Title.DisplayOrder (int) Required, 15], [Property: Title.IsActive (bool) Required, 16], [Property: Title.IsDefault (bool) Required, 17], [Property: Title.Name (string) Required MaxLength(150), 18] }
SELECT e.Id, e.DefaultHomePageId, e.FirstName, e.LastName, e.TitleId, h.Id, h.Code, h.DisplayOrder, h.IsActive, h.IsDefault, h.Name, h.OrganisationAdminOnly, h.RedirectPage, t.Id, t.Code, t.DisplayOrder, t.IsActive, t.IsDefault, t.Name
FROM Employee AS e
INNER JOIN HomePage AS h ON e.DefaultHomePageId == h.Id
LEFT JOIN Title AS t ON e.TitleId == t.Id) | Resolver: c => new RelationalCommandCache(
c.Dependencies.MemoryCache,
c.RelationalDependencies.QuerySqlGeneratorFactory,
c.RelationalDependencies.RelationalParameterBasedSqlProcessorFactory,
Client Projections:
0 -> Dictionary<IProperty, int> { [Property: Employee.Id (int?) Required PK AfterSave:Throw ValueGenerated.OnAdd, 0], [Property: Employee.DefaultHomePageId (int) Required FK Index, 1], [Property: Employee.FirstName (string) MaxLength(32), 2], [Property: Employee.LastName (string) MaxLength(32), 3], [Property: Employee.TitleId (int?) FK Index, 4] }
1 -> Dictionary<IProperty, int> { [Property: HomePage.Id (int?) Required PK AfterSave:Throw ValueGenerated.OnAdd, 5], [Property: HomePage.Code (string) Required MaxLength(16), 6], [Property: HomePage.DisplayOrder (int) Required, 7], [Property: HomePage.IsActive (bool) Required, 8], [Property: HomePage.IsDefault (bool) Required, 9], [Property: HomePage.Name (string) Required MaxLength(150), 10], [Property: HomePage.OrganisationAdminOnly (bool) Required, 11], [Property: HomePage.RedirectPage (int) Required, 12] }
2 -> Dictionary<IProperty, int> { [Property: Title.Id (int?) Required PK AfterSave:Throw ValueGenerated.OnAdd, 13], [Property: Title.Code (string) Required MaxLength(16), 14], [Property: Title.DisplayOrder (int) Required, 15], [Property: Title.IsActive (bool) Required, 16], [Property: Title.IsDefault (bool) Required, 17], [Property: Title.Name (string) Required MaxLength(150), 18] }
SELECT e.Id, e.DefaultHomePageId, e.FirstName, e.LastName, e.TitleId, h.Id, h.Code, h.DisplayOrder, h.IsActive, h.IsDefault, h.Name, h.OrganisationAdminOnly, h.RedirectPage, t.Id, t.Code, t.DisplayOrder, t.IsActive, t.IsDefault, t.Name
FROM Employee AS e
INNER JOIN HomePage AS h ON e.DefaultHomePageId == h.Id
LEFT JOIN Title AS t ON e.TitleId == t.Id,
False,
new HashSet<string>(
new string[]{ },
StringComparer.Ordinal
)
)].GetRelationalCommandTemplate(parameters),
readerColumns: null,
shaper: (queryContext, dataReader, resultContext, resultCoordinator) =>
{
Employee entity;
HomePage entity;
Title entity;
entity =
{
MaterializationContext materializationContext1;
IEntityType entityType1;
Employee instance1;
InternalEntityEntry entry1;
bool hasNullKey1;
materializationContext1 = new MaterializationContext(
[LIFTABLE Constant: ValueBuffer | Resolver: _ => (object)ValueBuffer.Empty],
queryContext.Context
);
instance1 = default(Employee);
entry1 = queryContext.TryGetEntry(
key: [LIFTABLE Constant: Key: Employee.Id PK | Resolver: c => c.Dependencies.Model.FindEntityType("EF_Core_8_Issue.DbSetEntities.Employee").FindPrimaryKey()],
keyValues: new object[]{ try { (object)dataReader.GetInt32(0) } catch (Exception) { ... } },
throwOnNullKey: True,
hasNullKey: hasNullKey1);
!(hasNullKey1) ? entry1 != default(InternalEntityEntry) ?
{
entityType1 = entry1.EntityType;
return instance1 = (Employee)entry1.Entity;
} :
{
ISnapshot shadowSnapshot1;
shadowSnapshot1 = [LIFTABLE Constant: Snapshot | Resolver: _ => Snapshot.Empty];
entityType1 = [LIFTABLE Constant: EntityType: Employee | Resolver: namelessParameter{0} => namelessParameter{0}.Dependencies.Model.FindEntityType("EF_Core_8_Issue.DbSetEntities.Employee")];
instance1 = switch (entityType1)
{
case [LIFTABLE Constant: EntityType: Employee | Resolver: namelessParameter{1} => namelessParameter{1}.Dependencies.Model.FindEntityType("EF_Core_8_Issue.DbSetEntities.Employee")]:
{
return
{
Employee instance;
instance = new Employee();
instance.<Id>k__BackingField = try { (int?)dataReader.GetInt32(0) } catch (Exception) { ... } ;
instance.<DefaultHomePageId>k__BackingField = try { dataReader.GetInt32(1) } catch (Exception) { ... } ;
instance.<FirstName>k__BackingField = try { dataReader.IsDBNull(2) ? default(string) : dataReader.GetString(2) } catch (Exception) { ... } ;
instance.<LastName>k__BackingField = try { dataReader.IsDBNull(3) ? default(string) : dataReader.GetString(3) } catch (Exception) { ... } ;
instance.<TitleId>k__BackingField = try { dataReader.IsDBNull(4) ? default(int?) : (int?)dataReader.GetInt32(4) } catch (Exception) { ... } ;
(instance is IInjectableService) ? ((IInjectableService)instance).Injected(
context: materializationContext1.Context,
entity: instance,
queryTrackingBehavior: TrackAll,
structuralType: [LIFTABLE Constant: EntityType: Employee | Resolver: namelessParameter{2} => namelessParameter{2}.Dependencies.Model.FindEntityType("EF_Core_8_Issue.DbSetEntities.Employee")]) : default(void);
return instance;
}}
default:
default(Employee)
}
;
entry1 = entityType1 == default(IEntityType) ? default(InternalEntityEntry) : queryContext.StartTracking(
entityType: entityType1,
entity: instance1,
snapshot: shadowSnapshot1);
return instance1;
} : default(void);
return instance1;
};
entity =
{
MaterializationContext materializationContext2;
IEntityType entityType2;
HomePage instance2;
InternalEntityEntry entry2;
bool hasNullKey2;
materializationContext2 = new MaterializationContext(
[LIFTABLE Constant: ValueBuffer | Resolver: _ => (object)ValueBuffer.Empty],
queryContext.Context
);
instance2 = default(HomePage);
entry2 = queryContext.TryGetEntry(
key: [LIFTABLE Constant: Key: HomePage.Id PK | Resolver: c => c.Dependencies.Model.FindEntityType("EF_Core_8_Issue.DbSetEntities.HomePage").FindPrimaryKey()],
keyValues: new object[]{ try { (object)dataReader.GetInt32(5) } catch (Exception) { ... } },
throwOnNullKey: True,
hasNullKey: hasNullKey2);
!(hasNullKey2) ? entry2 != default(InternalEntityEntry) ?
{
entityType2 = entry2.EntityType;
return instance2 = (HomePage)entry2.Entity;
} :
{
ISnapshot shadowSnapshot2;
shadowSnapshot2 = [LIFTABLE Constant: Snapshot | Resolver: _ => Snapshot.Empty];
entityType2 = [LIFTABLE Constant: EntityType: HomePage | Resolver: namelessParameter{3} => namelessParameter{3}.Dependencies.Model.FindEntityType("EF_Core_8_Issue.DbSetEntities.HomePage")];
instance2 = switch (entityType2)
{
case [LIFTABLE Constant: EntityType: HomePage | Resolver: namelessParameter{4} => namelessParameter{4}.Dependencies.Model.FindEntityType("EF_Core_8_Issue.DbSetEntities.HomePage")]:
{
return
{
HomePage instance;
instance = new HomePage();
instance.<Id>k__BackingField = try { (int?)dataReader.GetInt32(5) } catch (Exception) { ... } ;
instance.<Code>k__BackingField = try { dataReader.GetString(6) } catch (Exception) { ... } ;
instance.<DisplayOrder>k__BackingField = try { dataReader.GetInt32(7) } catch (Exception) { ... } ;
instance.<IsActive>k__BackingField = try { dataReader.GetBoolean(8) } catch (Exception) { ... } ;
instance.<IsDefault>k__BackingField = try { dataReader.GetBoolean(9) } catch (Exception) { ... } ;
instance.<Name>k__BackingField = try { dataReader.GetString(10) } catch (Exception) { ... } ;
instance.<OrganisationAdminOnly>k__BackingField = try { dataReader.GetBoolean(11) } catch (Exception) { ... } ;
instance.<RedirectPage>k__BackingField = try { dataReader.GetInt32(12) } catch (Exception) { ... } ;
(instance is IInjectableService) ? ((IInjectableService)instance).Injected(
context: materializationContext2.Context,
entity: instance,
queryTrackingBehavior: TrackAll,
structuralType: [LIFTABLE Constant: EntityType: HomePage | Resolver: namelessParameter{5} => namelessParameter{5}.Dependencies.Model.FindEntityType("EF_Core_8_Issue.DbSetEntities.HomePage")]) : default(void);
return instance;
}}
default:
default(HomePage)
}
;
entry2 = entityType2 == default(IEntityType) ? default(InternalEntityEntry) : queryContext.StartTracking(
entityType: entityType2,
entity: instance2,
snapshot: shadowSnapshot2);
return instance2;
} : default(void);
return instance2;
};
entity =
{
MaterializationContext materializationContext3;
IEntityType entityType3;
Title instance3;
InternalEntityEntry entry3;
bool hasNullKey3;
materializationContext3 = new MaterializationContext(
[LIFTABLE Constant: ValueBuffer | Resolver: _ => (object)ValueBuffer.Empty],
queryContext.Context
);
instance3 = default(Title);
entry3 = queryContext.TryGetEntry(
key: [LIFTABLE Constant: Key: Title.Id PK | Resolver: c => c.Dependencies.Model.FindEntityType("EF_Core_8_Issue.DbSetEntities.Title").FindPrimaryKey()],
keyValues: new object[]{ try { dataReader.IsDBNull(13) ? default(object) : (object)dataReader.GetInt32(13) } catch (Exception) { ... } },
throwOnNullKey: False,
hasNullKey: hasNullKey3);
!(hasNullKey3) ? entry3 != default(InternalEntityEntry) ?
{
entityType3 = entry3.EntityType;
return instance3 = (Title)entry3.Entity;
} :
{
ISnapshot shadowSnapshot3;
shadowSnapshot3 = [LIFTABLE Constant: Snapshot | Resolver: _ => Snapshot.Empty];
entityType3 = [LIFTABLE Constant: EntityType: Title | Resolver: namelessParameter{6} => namelessParameter{6}.Dependencies.Model.FindEntityType("EF_Core_8_Issue.DbSetEntities.Title")];
instance3 = switch (entityType3)
{
case [LIFTABLE Constant: EntityType: Title | Resolver: namelessParameter{7} => namelessParameter{7}.Dependencies.Model.FindEntityType("EF_Core_8_Issue.DbSetEntities.Title")]:
{
return
{
Title instance;
instance = new Title();
instance.<Id>k__BackingField = try { dataReader.IsDBNull(13) ? default(int?) : (int?)dataReader.GetInt32(13) } catch (Exception) { ... } ;
instance.<Code>k__BackingField = try { dataReader.IsDBNull(14) ? default(string) : dataReader.GetString(14) } catch (Exception) { ... } ;
instance.<DisplayOrder>k__BackingField = try { dataReader.IsDBNull(15) ? default(int) : dataReader.GetInt32(15) } catch (Exception) { ... } ;
instance.<IsActive>k__BackingField = try { dataReader.IsDBNull(16) ? default(bool) : dataReader.GetBoolean(16) } catch (Exception) { ... } ;
instance.<IsDefault>k__BackingField = try { dataReader.IsDBNull(17) ? default(bool) : dataReader.GetBoolean(17) } catch (Exception) { ... } ;
instance.<Name>k__BackingField = try { dataReader.IsDBNull(18) ? default(string) : dataReader.GetString(18) } catch (Exception) { ... } ;
(instance is IInjectableService) ? ((IInjectableService)instance).Injected(
context: materializationContext3.Context,
entity: instance,
queryTrackingBehavior: TrackAll,
structuralType: [LIFTABLE Constant: EntityType: Title | Resolver: namelessParameter{8} => namelessParameter{8}.Dependencies.Model.FindEntityType("EF_Core_8_Issue.DbSetEntities.Title")]) : default(void);
return instance;
}}
default:
default(Title)
}
;
entry3 = entityType3 == default(IEntityType) ? default(InternalEntityEntry) : queryContext.StartTracking(
entityType: entityType3,
entity: instance3,
snapshot: shadowSnapshot3);
return instance3;
} : default(void);
return instance3;
};
ShaperProcessingExpressionVisitor.IncludeReference<Employee, Employee, HomePage>(
queryContext: queryContext,
entity: entity,
relatedEntity: entity,
navigation: [LIFTABLE Constant: Navigation: Employee.DefaultHomePage (HomePage) ToPrincipal HomePage | Resolver: namelessParameter{9} => namelessParameter{9}.Dependencies.Model.FindEntityType("EF_Core_8_Issue.DbSetEntities.Employee").FindNavigation("DefaultHomePage")],
inverseNavigation: default(INavigation),
fixup: (namelessParameter{10}, namelessParameter{11}) =>
{
return namelessParameter{10}.<DefaultHomePage>k__BackingField = namelessParameter{11};
},
trackingQuery: True);
ShaperProcessingExpressionVisitor.IncludeReference<Employee, Employee, Title>(
queryContext: queryContext,
entity: entity,
relatedEntity: entity,
navigation: [LIFTABLE Constant: Navigation: Employee.Title (Title) ToPrincipal Title | Resolver: namelessParameter{12} => namelessParameter{12}.Dependencies.Model.FindEntityType("EF_Core_8_Issue.DbSetEntities.Employee").FindNavigation("Title")],
inverseNavigation: default(INavigation),
fixup: (namelessParameter{13}, namelessParameter{14}) =>
{
return namelessParameter{13}.<Title>k__BackingField = namelessParameter{14};
},
trackingQuery: True);
return entity;
},
contextType: EF_Core_8_Issue.DatabaseContext,
standAloneStateManager: False,
detailedErrorsEnabled: True,
threadSafetyChecksEnabled: True)'
dbug: 15/11/2024 12:36:42.630 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command)
Creating DbCommand for 'ExecuteReader'.
dbug: 15/11/2024 12:36:42.635 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
Created DbCommand for 'ExecuteReader' (4ms).
dbug: 15/11/2024 12:36:42.636 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command)
Initialized DbCommand for 'ExecuteReader' (5ms).
dbug: 15/11/2024 12:36:42.637 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [e].[Id], [e].[DefaultHomePageId], [e].[FirstName], [e].[LastName], [e].[TitleId], [h].[Id], [h].[Code], [h].[DisplayOrder], [h].[IsActive], [h].[IsDefault], [h].[Name], [h].[OrganisationAdminOnly], [h].[RedirectPage], [t].[Id], [t].[Code], [t].[DisplayOrder], [t].[IsActive], [t].[IsDefault], [t].[Name]
FROM [Employee] AS [e]
INNER JOIN [HomePage] AS [h] ON [e].[DefaultHomePageId] = [h].[Id]
LEFT JOIN [Title] AS [t] ON [e].[TitleId] = [t].[Id]
info: 15/11/2024 12:36:42.640 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (3ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [e].[Id], [e].[DefaultHomePageId], [e].[FirstName], [e].[LastName], [e].[TitleId], [h].[Id], [h].[Code], [h].[DisplayOrder], [h].[IsActive], [h].[IsDefault], [h].[Name], [h].[OrganisationAdminOnly], [h].[RedirectPage], [t].[Id], [t].[Code], [t].[DisplayOrder], [t].[IsActive], [t].[IsDefault], [t].[Name]
FROM [Employee] AS [e]
INNER JOIN [HomePage] AS [h] ON [e].[DefaultHomePageId] = [h].[Id]
LEFT JOIN [Title] AS [t] ON [e].[TitleId] = [t].[Id]
dbug: 15/11/2024 12:36:42.642 RelationalEventId.DataReaderClosing[20301] (Microsoft.EntityFrameworkCore.Database.Command)
Closing data reader to 'EF8_Issue_Testing' on server '.'.
dbug: 15/11/2024 12:36:42.642 RelationalEventId.DataReaderDisposing[20300] (Microsoft.EntityFrameworkCore.Database.Command)
A data reader for 'EF8_Issue_Testing' on server '.' is being disposed after spending 1ms reading results.
dbug: 15/11/2024 12:36:42.642 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command)
Creating DbCommand for 'ExecuteNonQuery'.
dbug: 15/11/2024 12:36:42.642 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
Created DbCommand for 'ExecuteNonQuery' (0ms).
dbug: 15/11/2024 12:36:42.642 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command)
Initialized DbCommand for 'ExecuteNonQuery' (0ms).
dbug: 15/11/2024 12:36:42.643 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
SET IDENTITY_INSERT [Employee] OFF
info: 15/11/2024 12:36:42.643 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SET IDENTITY_INSERT [Employee] OFF
dbug: 15/11/2024 12:36:42.644 RelationalEventId.TransactionCommitting[20210] (Microsoft.EntityFrameworkCore.Database.Transaction)
Committing transaction.
dbug: 15/11/2024 12:36:42.647 RelationalEventId.TransactionCommitted[20202] (Microsoft.EntityFrameworkCore.Database.Transaction)
Committed transaction.
dbug: 15/11/2024 12:36:42.649 RelationalEventId.ConnectionClosing[20002] (Microsoft.EntityFrameworkCore.Database.Connection)
Closing connection to database 'EF8_Issue_Testing' on server '.'.
dbug: 15/11/2024 12:36:42.650 RelationalEventId.ConnectionClosed[20003] (Microsoft.EntityFrameworkCore.Database.Connection)
Closed connection to database 'EF8_Issue_Testing' on server '.' (0ms).
@stevejackson-daviesgroup The relationships between Employee and Title, and between Employee and HomePage are configured as one-to-one relationships:
builder.HasOne(e => e.Title).WithOne();
builder.HasOne(e => e.DefaultHomePage).WithOne();
This means that each Title object can have at most one Employee object associated with it. However, it looks like the relationships should be one-to-many, so that many Employees can have the same Title, for example. See Introduction to relationships for more info.
How the heck did I miss that! :(
Still odd behaviour though as it only messes up with the first item added each time. But I can live with that - I've tested with the sample repo and yeah, it works as one would expect. Now I'll need to go through the main code and make sure all models are configured correctly...and make sure to RTFM again.
Many thanks - no idea why I couldn't see that myself, you just saved me from my own stupidity!
Hi, I hope somebody can shed light on a rather serious problem that I have run into.
We have been migrating a project from .NET Framework 4.6 to .NET 8.0 - most things have gone well, till this. Part of the project involves the creation of seed data for dev/test/sales purposes, and it is in this area that I've hit a very confusing problem.
The seed data is fed from a set of IList objects which are then converted into IList objects using AutoMapper - this works perfectly well and half of the seed data is being saved into the target SQL Server database with no issue. Sadly it has now hit a roadblock, in an effort to try and see if it was our code that was causing the issue I created a very small project to try and replicate the problem - which I was able to do, so at least this is not caused by the larger code base.
The specific issue - and the one that is replicated in the linked repo - is that the saving of Title and Homepage data entities works (all data present and correct in database) BUT when saving Employee data the 1st record goes AWOL and (of the 4 records in the linked repo) the 3rd record ends up with a NULL for TitleId - even though the source data does have a title ID set.
While this is all in the code, the seed data for Employees is defined like this:
But, this is what finds it's way into SQL server. 1 record missing and 1 that has no titleId - even though every record does have a title ID assigned in the seed data. Interestingly if I change the order of the employee seed data it is ALWAYS the 1st record that goes missing - not ID 1 but whatever entity was 1st in the IList.
GitHub Repo with sample project
If you would rather the code was pasted rather thank linked to please let me know.
Really hope somebody can at least explain what is going on here, I'm kinda loosing my mind over this issue!
EF Core version: 9.0.0 (was also present in 8.x we tried upgrading today to see if it fixed the problem) Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: .NET 8.0 Operating system: Windows 10 IDE: Visual Studio 2022 17.12.0