You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now, it is impossible to access an EntityEntry (via Context.Entry(obj)) for a SharedEntity and this prevents us from changing states of entries.
(Not really necessary to understand the issue, but I need to access the EntityEntry of the shared entity because I want to set the state of the shared entity to Added while keeping related entities to Unchanged)
Reproducible example
privateclassTestEntity{publicintID{get;set;}publicICollection<TestShared>Shared{get;set;}}privateclassTestShared{publicintID{get;set;}publicstringProperty{get;set;}}privateclassSharedEntityContext:DbContext{publicDbSet<TestEntity>Entities{get;set;}protectedoverridevoidOnConfiguring(DbContextOptionsBuilderoptionsBuilder){optionsBuilder.UseSqlite(":memory:");}protectedoverridevoidOnModelCreating(ModelBuildermodelBuilder){modelBuilder.SharedTypeEntity<TestShared>("EntityShared").HasKey(x =>x.ID);modelBuilder.SharedTypeEntity<TestShared>("EntityShared").HasOne<TestEntity>().WithMany(x =>x.Shared).OnDelete(DeleteBehavior.Cascade);}}[Fact]publicvoidSharedEntityEntryTest(){usingSharedEntityContextcontext=new();TestEntityshow=new();context.Entry(show);// This does not throw;TestSharedid=new();context.Entry(id);// This throws.}
Stack Traces
System.InvalidOperationException
The entity type 'TestShared' was not found. Ensure that the entity type has been added to the model.
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.GetOrCreateEntry(Object entity)
at Microsoft.EntityFrameworkCore.DbContext.EntryWithoutDetectChanges[TEntity](TEntity entity)
at Microsoft.EntityFrameworkCore.DbContext.Entry[TEntity](TEntity entity)
at Kyoo.Tests.Database.GlobalTests.SharedEntityEntryTest() in /home/anonymus-raccoon/Projects/Kyoo/Kyoo/Kyoo.Tests/Database/SpecificTests/SanityTests.cs:line 82
Include provider and version information
EF Core version: 5.0.8
Database provider: Microsoft.EntityFrameworkCore.Sqlite 5.0.8 & Npgsql.EntityFrameworkCore.PostgreSQL 5.0.7
Target framework: NET 5.0
Operating system: Linux
IDE: Rider
The text was updated successfully, but these errors were encountered:
Note for triage: Attach will always track the entity instance. We should consider an overload of "Entry" that takes the shared type name. This would return an EntityEntry without necessarily tracking it, such that things like shadow PKs can be set before starting to track.
Get an EntityEntry for Shared Entity Types
Right now, it is impossible to access an EntityEntry (via
Context.Entry(obj)
) for a SharedEntity and this prevents us from changing states of entries.(Not really necessary to understand the issue, but I need to access the EntityEntry of the shared entity because I want to set the state of the shared entity to Added while keeping related entities to Unchanged)
Reproducible example
Stack Traces
Include provider and version information
EF Core version: 5.0.8
Database provider: Microsoft.EntityFrameworkCore.Sqlite 5.0.8 & Npgsql.EntityFrameworkCore.PostgreSQL 5.0.7
Target framework: NET 5.0
Operating system: Linux
IDE: Rider
The text was updated successfully, but these errors were encountered: