[EF-88] Unknown discriminator value 'List`1' error Created: 12/Dec/23  Updated: 04/Jan/24

Status: Scheduled
Project: Entity Framework
Component/s: None
Affects Version/s: Public Preview 1
Fix Version/s: None

Type: Bug Priority: Unknown
Reporter: Chris Vigorito Assignee: Damien Guard
Resolution: Unresolved Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Thank you for your hard work on implementing this EF Core provider. 

I am attempting to use it within an ASP.NET Core application and running into an issue when entities have a List (or any ICollection) property. 

I can write such entities with no problem and they show up in the database as Objects with "_t: List`1" and "_v: Array". I can also query for them and they return and parse correctly in .NET. 

However, if I attempt to query for them without having written one such entity to the collection since application start, then I receive the error "Unknown discriminator value 'List`1'."

I did some searching and found this post: https://stackoverflow.com/questions/43312039/unknown-discriminator-value-mongodb  

It suggests the issue is that the class must be mapped in the Bson class map before the first read occurs. When an entity is written, this class map is created under the hood, which is why it works after a write.

The post (and documentation for the C# driver) suggests to manually map the class map using BsonClassMap.RegisterClassMap<EntityType>(). However, I tried putting this in my startup code and I still see the error. Should this approach work with the EF Core provider, or is there another way to do this? 

If this is not supported currently, is there any workaround to avoid needing to do a write first?



 Comments   
Comment by Damien Guard [ 03/Jan/24 ]

Customer responded (via email due to permissions issue which is now hopefully fixed, quoting here)

Hi Damien,

Thanks for the clarification. For this specific issue I wasn't explicitly trying to use discriminators, but wondering whether it was possible to write .NET collection properties without doing so or via some workaround. It sounds like only pure array types for collections will work for now?

I'm attaching a minimal example. If you run the application and call the "write" endpoint once to write an entity to the db, then restart the application and call the read endpoint, it will trigger the error. Everything works properly though if you remove the List<string> property from the entity class and only use array type properties.

My question was mainly whether, since it works once a write has been made, there's a way to produce the same behavior without having to call write first.

For my general use case I will likely need to make use of discriminators and value converters, so it sounds like I'll need to stick with the C# driver for now. But I will definitely keep an eye out for new releases. I would be great to be able to use the EF Core driver when it's ready. Is there a rough timeline for the next preview release?

Thanks for your help.

Best,
Chris

Comment by Damien Guard [ 18/Dec/23 ]

Hi Chris.

Type discriminator support is not included in the EF provider yet - we're hoping to get it into the next release.

Additionally similar functionality that the C# Driver provides - such as discriminators and Class Maps are not supported when using the EF provider as many of these features fundamentally provide the same features in radically different ways.

Did you intend to actually use type discriminators? If not could you please provide a minimal repro so I can further investigate as to what might be causing the issue.

Thanks

Damien

Generated at Thu Feb 08 08:26:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.