Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EF Core 7 CosmosDb - Using entity with SmartEnum property causes EF Core to create entries in another container #338

Open
nhwilly opened this issue Nov 13, 2022 · 0 comments

Comments

@nhwilly
Copy link

nhwilly commented Nov 13, 2022

If anyone is interested, I can write up a whole thing, but I narrowed it down.

In EF Core for Cosmos, OwnsMany properties are automatically embedded in the document (item) as an array.

In my case, I had an Invitation aggregate that had a list of InvitationEvents. Each InvitationEvent contained a DateTimeOffset and an InvitationEventType, which was a SmartEnum. Defined as below:

[JsonConverter(typeof(SmartEnumNameConverter<InvitationEventType, int>))]
public InvitationEventType InvitationEventType { get; init; }

What was happening was that each event was being written to the default Cosmos container with a default Guid value. That is, the Invitation ended up in the proper container and the InvitationEvents ended up in the default container. Wild.

If I changed that SmartEnum to a simple enum, my document contained a collection of InvitationEvents as expected, with no configuration.

If you're seeing something nutty with your child objects, I hope this helps.

p.s. Yes, I'm using modelBuilder.ConfigureSmartEnum();
p.p.s. No, I did not try this with EF Core on a SQL Provider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant