-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Regression going from .NET/EF 8 to 9 with CosmosDb, will no longer save/load Ulid and Custom struct types #34936
Comments
Note for team: in previous releases, the Cosmos type mapper allowed value type. We brought this in line with other type mappers to only map types that are known to be compatible. However, value types can be written so they "just work" in Cosmos, and we are now blocking that. We should document this as a breaking change, if we have not already done so. I will investigate workarounds and the potential for new API to support any serializable type explicitly. I will also investigate the use of |
Thanks @ajcvickers, any work arounds would be appreciate as I'm in the midst of updating everything to .NET 9. Do you think something will be in the works for this before GA or is that just cutting it to fine? |
@mip1983 GA is basically completely finished at this point - but we'll investigate and get back to you soon. |
@mip1983 As a workaround, you can replace the Cosmos type mapper with one that will allow your types. This requires the use of internal code, but should be safe for use with EF9. We will investigate this further as part of the EF10 release. Ultimately, we may support this through custom serialization, but we're not sure exactly what that will look like. To use a custom type mapper, use protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.ReplaceService<ITypeMappingSource, ReplacementCosmosTypeMappingSource>();
} Using something like this: public class ReplacementCosmosTypeMappingSource(TypeMappingSourceDependencies dependencies)
: CosmosTypeMappingSource(dependencies)
{
protected override CoreTypeMapping? FindMapping(in TypeMappingInfo mappingInfo)
{
var mapping = base.FindMapping(mappingInfo);
if (mapping is null
&& mappingInfo.ClrType?.IsValueType == true)
{
return new CosmosTypeMapping(mappingInfo.ClrType);
}
return mapping;
}
} Note that there is another option for a workaround, which is to use value converters. However, value converters cannot generate JSON structure, such as you use for |
Note from team meeting: closing this as by-design. Custom serialization is tracked by #17306. |
Creating this as a separate issue from #31376 , described below with repro (https://github.com/mip1983/CosmosDbEF)
Originally posted by @mip1983 in #31376
The text was updated successfully, but these errors were encountered: