Owned Types get attached multiple times as different types #26257
Labels
area-cosmos
area-query
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-bug
Milestone
I try to implement a simple activity stream with EF and Cosmos DB. This is a very simplified version of the structure I want to save:
There are different types of activities, but all have the same base class. The
Type
property is used as the discriminator. All activities have anActor
property, but actors can be of different types with different properties. All actors have the same base class.As far as I understand it's not possible to use a discriminator with Owned Types. That's why I created activity classes with specific actor types.
Adding activities to Cosmos DB works already and the structure looks like described before. But when I try to read the items, I get the following exception:
It seems that EF tries to attach the actors of both activities as type
UserActor
AND typeDriverActor
at the same time. TheUserActor
has noLicenseId
and that's why the exception gets thrown.This is the log output when I try to read the two items I showed before:
As you can see, both the
UserActor
and theDriverActor
appear twice. But there is only one item withUserActor
and one withDriverActor
.The debug view of the model looks fine to me:
This is a full working Program.cs file to reproduce the issue:
EF Core version: 6.0.0-rc.1.21452.10
Database provider: (e.g. Microsoft.EntityFrameworkCore.Cosmos)
Target framework: (e.g. .NET 6.0)
Operating system: Windows 11
IDE: (e.g. Visual Studio 2022 17.0.0 Preview 4.1)
The text was updated successfully, but these errors were encountered: