-
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
A problem with owned Type and SetValueConverter at runtime. #25532
Comments
Duplicate of #13947 |
In 6.0.0-preview6 we shipped #10784 which allows you to call |
Thanks for your replies. However, "Properties().HaveConversion()" cannot solve my problem, because what I want to do is to SetValueConverter at runtime. foreach (var navigation in entityType.GetNavigations())
{
Type propertyType = navigation.ClrType;
if (IsStronglyTypedId(propertyType))
{
Type valueType = typeof(Guid);
var converter = StronglyTypedIdConverters.GetOrAdd(
propertyType,
_ => CreateStronglyTypedIdConverter(propertyType, valueType));
navigation.SetValueConverter(converter);//error: no such method
}
} |
I tried to implement Strongly-Typed-Id in EF Core.
The following code works well:
However, when I tried to set valueconverters for every Strongly-Typed-Id properties at runtime, the code is as following:
Step one: Remove "builder.Property(p => p.Id).HasConversion(id => id.Value, value => new CategoryId(value));" from CategoryConfig
Step Two:
Step Three: invoke AddStronglyTypedIdConversions in OnModelCreating
The code above cannot work properly, and exception 'The entity type XXXId requires a primary key to be defined.' will be thrown.
Because entityType.GetProperties() only returns scalar properties, the Id property of Category is not included in the returned values of entityType.GetProperties(). I can get the Id property of Category with entityType.GetNavigations(), but IMutableNavigation cannot invoke the SetValueConverter method.
.NET Version:.NET 5
EF Core version:5.0.9
My questioin is :how can I set ValueConverter for non-scalar property at runtime?
Thanks.
The text was updated successfully, but these errors were encountered: