You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently i implemented this ValueConversion interface with the support of custom attributes and reflection. Maybe the following code can be adopted in the next release.
FieldConverterAttribute constructor prototype (maybe there is already an apropate deifnition in EF for this):
publicFieldConvertAttribute(Type targetType)
Custom OnModelCreatedImpl implementation:
partialvoidOnModelCreatedImpl(ModelBuildermodelBuilder){// retrieve needed interfacesvarvalueConverter=this.GetService<IValueConverterSelector>();// process attributesforeach(var entityType in modelBuilder.Model.GetEntityTypes()){foreach(var property in entityType.GetProperties()){// check for field convertersvarattributes= property?.PropertyInfo?.GetCustomAttributes(typeof(FieldConvertAttribute),false);if(attributes?.FirstOrDefault()is FieldConvertAttribute convertAttribute){varconverterInfos= valueConverter.Select(property.ClrType, convertAttribute.TargetType);// select first converter if there is anyif(converterInfos.DefaultIfEmpty().FirstOrDefault()is ValueConverterInfo converterInfo){// create and apply convertervarconverter= converterInfo.Create();
property.SetValueConverter(converter);}else{// maybe look for another converter sources or throw an exception}}}}}
https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-5.0/whatsnew#modelbuilder-api-for-value-comparers
The text was updated successfully, but these errors were encountered: