/// <summary> /// Creates a new instance of <see cref="RelationalTypeMappingInfo" /> with the given <see cref="ValueConverterInfo" />. /// </summary> /// <param name="source"> The source info. </param> /// <param name="builtInConverter"> The converter to apply. </param> protected RelationalTypeMappingInfo( [NotNull] RelationalTypeMappingInfo source, ValueConverterInfo builtInConverter) : base(source, builtInConverter) { StoreTypeName = source.StoreTypeName; }
/// <summary> /// Creates a new instance of <see cref="RelationalTypeMappingInfo" /> with the given <see cref="ValueConverterInfo" />. /// </summary> /// <param name="source"> The source info. </param> /// <param name="converter"> The converter to apply. </param> protected RelationalTypeMappingInfo( [NotNull] RelationalTypeMappingInfo source, ValueConverterInfo converter) : base(source, converter) { var mappingHints = converter.MappingHints; StoreTypeName = source.StoreTypeName; StoreTypeNameBase = ParseStoreTypeName(source.StoreTypeName, out _parsedSize, out _parsedPrecision, out _parsedScale, out _isMax); IsFixedLength = source.IsFixedLength ?? (mappingHints as RelationalConverterMappingHints)?.IsFixedLength; }
/// <summary> /// Creates a new instance of <see cref="RelationalTypeMappingInfo" /> with the given <see cref="ValueConverterInfo" />. /// </summary> /// <param name="source"> The source info. </param> /// <param name="builtInConverter"> The converter to apply. </param> protected RelationalTypeMappingInfo( [NotNull] RelationalTypeMappingInfo source, ValueConverterInfo builtInConverter) : base(source, builtInConverter) { // ReSharper disable once VirtualMemberCallInConstructor var mappingHints = ValueConverterInfo?.MappingHints ?? default; StoreTypeName = source.StoreTypeName; StoreTypeNameBase = ParseStoreTypeName(source.StoreTypeName, out _parsedSize, out _parsedPrecision, out _parsedScale, out _isMax); IsFixedLength = source.IsFixedLength ?? (mappingHints as RelationalConverterMappingHints)?.IsFixedLength; }
/// <summary> /// Creates a new instance of <see cref="TypeMappingInfo" />. /// </summary> /// <param name="property"> The property for which mapping is needed. </param> /// <param name="modelClrType"> The CLR type in the model for which mapping is needed. </param> public TypeMappingInfo( [CanBeNull] IProperty property = null, [CanBeNull] Type modelClrType = null) { Property = property; if (property != null) { var principals = property.FindPrincipals().ToList(); StoreClrType = principals .Select(p => p.GetStoreClrType()) .FirstOrDefault(t => t != null) ?.UnwrapNullableType(); _customConverter = principals .Select(p => p.GetValueConverter()) .FirstOrDefault(c => c != null); var mappingHints = _customConverter?.MappingHints ?? default; if (_customConverter != null) { ValueConverterInfo = new ValueConverterInfo( _customConverter.ModelType, _customConverter.StoreType, i => _customConverter, mappingHints); } IsKeyOrIndex = property.IsKeyOrForeignKey() || property.IsIndex(); Size = CalculateSize( mappingHints, principals.Select(p => p.GetMaxLength()).FirstOrDefault(t => t != null) ?? mappingHints.Size); IsUnicode = principals.Select(p => p.IsUnicode()).FirstOrDefault(t => t != null) ?? mappingHints.IsUnicode; IsRowVersion = property.IsConcurrencyToken && property.ValueGenerated == ValueGenerated.OnAddOrUpdate; IsFixedLength = mappingHints.IsFixedLength; Precision = mappingHints.Precision; Scale = mappingHints.Scale; } ModelClrType = (modelClrType ?? property?.ClrType)?.UnwrapNullableType(); }
/// <summary> /// Creates a new instance of <see cref="TypeMappingInfo" />. /// </summary> /// <param name="property"> The property for which mapping is needed. </param> protected TypeMappingInfo([NotNull] IProperty property) { Check.NotNull(property, nameof(property)); Property = property; MemberInfo = property.GetIdentifyingMemberInfo(); var principals = property.FindPrincipals().ToList(); ConfiguredProviderClrType = principals .Select(p => p.GetProviderClrType()) .FirstOrDefault(t => t != null) ?.UnwrapNullableType(); _customConverter = principals .Select(p => p.GetValueConverter()) .FirstOrDefault(c => c != null); var mappingHints = _customConverter?.MappingHints ?? default; if (_customConverter != null) { ValueConverterInfo = new ValueConverterInfo( _customConverter.ModelClrType, _customConverter.ProviderClrType, i => _customConverter, mappingHints); } IsKeyOrIndex = property.IsKeyOrForeignKey() || property.IsIndex(); Size = principals.Select(p => p.GetMaxLength()).FirstOrDefault(t => t != null) ?? mappingHints.Size; IsUnicode = principals.Select(p => p.IsUnicode()).FirstOrDefault(t => t != null) ?? mappingHints.IsUnicode; IsRowVersion = property.IsConcurrencyToken && property.ValueGenerated == ValueGenerated.OnAddOrUpdate; IsFixedLength = mappingHints.IsFixedLength; Precision = mappingHints.Precision; Scale = mappingHints.Scale; ModelClrType = property.ClrType.UnwrapNullableType(); ProviderClrType = CreateProviderClrType(); }
/// <summary> /// Creates a new instance of <see cref="RelationalTypeMappingInfo" /> with the given <see cref="ValueConverterInfo" />. /// </summary> /// <param name="source"> The source info. </param> /// <param name="converter"> The converter to apply. </param> public RelationalTypeMappingInfo( RelationalTypeMappingInfo source, ValueConverterInfo converter) { _coreTypeMappingInfo = new TypeMappingInfo( source._coreTypeMappingInfo, converter, source.IsUnicode, source.Size, source.Precision, source.Scale); var mappingHints = converter.MappingHints; StoreTypeName = source.StoreTypeName; StoreTypeNameBase = ParseStoreTypeName(source.StoreTypeName, out _parsedSize, out _parsedPrecision, out _parsedScale, out _isMax); IsFixedLength = source.IsFixedLength ?? (mappingHints as RelationalConverterMappingHints)?.IsFixedLength; }
/// <summary> /// Creates a new instance of <see cref="TypeMappingInfo" /> with the given <see cref="ValueConverterInfo" />. /// </summary> /// <param name="source"> The source info. </param> /// <param name="converter"> The converter to apply. </param> protected TypeMappingInfo( [NotNull] TypeMappingInfo source, ValueConverterInfo converter) { Check.NotNull(source, nameof(source)); Property = source.Property; IsRowVersion = source.IsRowVersion; IsKeyOrIndex = source.IsKeyOrIndex; MemberInfo = source.MemberInfo; var mappingHints = converter.MappingHints; Size = source.Size ?? mappingHints?.Size; IsUnicode = source.IsUnicode ?? mappingHints?.IsUnicode; Scale = source.Scale ?? mappingHints?.Scale; Precision = source.Precision ?? mappingHints?.Precision; ClrType = converter.ProviderClrType.UnwrapNullableType(); }
/// <summary> /// Creates a new instance of <see cref="TypeMappingInfo" /> with the given <see cref="ValueConverterInfo" />. /// </summary> /// <param name="source">The source info.</param> /// <param name="converter">The converter to apply.</param> /// <param name="unicode">Specifies Unicode or ANSI mapping, or <see langword="null" /> for default.</param> /// <param name="size">Specifies a size for the mapping, or <see langword="null" /> for default.</param> /// <param name="precision">Specifies a precision for the mapping, or <see langword="null" /> for default.</param> /// <param name="scale">Specifies a scale for the mapping, or <see langword="null" /> for default.</param> public TypeMappingInfo( TypeMappingInfo source, ValueConverterInfo converter, bool?unicode = null, int?size = null, int?precision = null, int?scale = null) { IsRowVersion = source.IsRowVersion; IsKeyOrIndex = source.IsKeyOrIndex; var mappingHints = converter.MappingHints; Size = size ?? source.Size ?? mappingHints?.Size; IsUnicode = unicode ?? source.IsUnicode ?? mappingHints?.IsUnicode; Scale = scale ?? source.Scale ?? mappingHints?.Scale; Precision = precision ?? source.Precision ?? mappingHints?.Precision; ClrType = converter.ProviderClrType.UnwrapNullableType(); }
/// <summary> /// Creates a new instance of <see cref="TypeMappingInfo" /> with the given <see cref="ValueConverterInfo" />. /// </summary> /// <param name="source"> The source info. </param> /// <param name="builtInConverter"> The converter to apply. </param> protected TypeMappingInfo( [NotNull] TypeMappingInfo source, ValueConverterInfo builtInConverter) { Check.NotNull(source, nameof(source)); Property = source.Property; ModelClrType = source.ModelClrType; ConfiguredProviderClrType = source.ConfiguredProviderClrType; IsRowVersion = source.IsRowVersion; IsKeyOrIndex = source.IsKeyOrIndex; if (source._customConverter != null) { _customConverter = source._customConverter; ValueConverterInfo = new ValueConverterInfo( _customConverter.ModelClrType, builtInConverter.ProviderClrType, i => _customConverter.ComposeWith(builtInConverter.Create()), builtInConverter.MappingHints == null ? _customConverter.MappingHints : builtInConverter.MappingHints.With(_customConverter.MappingHints)); } else { ValueConverterInfo = builtInConverter; } // ReSharper disable once VirtualMemberCallInConstructor var mappingHints = ValueConverterInfo?.MappingHints; Size = source.Size ?? mappingHints?.Size; IsUnicode = source.IsUnicode ?? mappingHints?.IsUnicode; Scale = source.Scale ?? mappingHints?.Scale; Precision = source.Precision ?? mappingHints?.Precision; ProviderClrType = CreateProviderClrType(); }
/// <summary> /// Creates a new instance of <see cref="TypeMappingInfo" /> with the given <see cref="ValueConverterInfo" />. /// </summary> /// <param name="source"> The source info. </param> /// <param name="builtInConverter"> The converter to apply. </param> protected TypeMappingInfo( [NotNull] TypeMappingInfo source, ValueConverterInfo builtInConverter) { Check.NotNull(source, nameof(source)); Property = source.Property; ModelClrType = source.ModelClrType; StoreClrType = source.StoreClrType; IsRowVersion = source.IsRowVersion; IsKeyOrIndex = source.IsKeyOrIndex; if (source._customConverter != null) { _customConverter = source._customConverter; ValueConverterInfo = new ValueConverterInfo( _customConverter.ModelType, builtInConverter.StoreClrType, i => _customConverter.ComposeWith(builtInConverter.Create()), _customConverter.MappingHints.With(builtInConverter.MappingHints)); } else { ValueConverterInfo = builtInConverter; } // ReSharper disable once VirtualMemberCallInConstructor var mappingHints = ValueConverterInfo?.MappingHints ?? default; Size = CalculateSize(mappingHints, source.Size ?? mappingHints.Size); IsUnicode = source.IsUnicode ?? mappingHints.IsUnicode; IsFixedLength = source.IsFixedLength ?? mappingHints.IsFixedLength; Scale = source.Scale ?? mappingHints.Scale; Precision = source.Precision ?? mappingHints.Precision; }
public override TypeMappingInfo WithConverter(ValueConverterInfo converterInfo) => new ConcreteRelationalTypeMappingInfo(this, converterInfo);
/// <summary> /// Returns a new <see cref="TypeMappingInfo" /> with the given converter applied. /// </summary> /// <param name="converterInfo"> The converter to apply. </param> /// <returns> The new mapping info. </returns> public abstract TypeMappingInfo WithBuiltInConverter(ValueConverterInfo converterInfo);
// Create an instance of the converter whenever it's requested. private static ValueConverter ValueConverterFactory(ValueConverterInfo info) => new IdentifierValueConverter <TDatabaseClrType>(info.MappingHints);
public override TypeMappingInfo WithBuiltInConverter(ValueConverterInfo converterInfo) => new ConcreteTypeMappingInfo(this, converterInfo);
private ConcreteTypeMappingInfo(ConcreteTypeMappingInfo source, ValueConverterInfo builtInConverter) : base(source, builtInConverter) { }
/// <summary> /// Returns a new <see cref="RelationalTypeMappingInfo" /> with the given converter applied. /// </summary> /// <param name="converterInfo"> The converter to apply. </param> /// <returns> The new mapping info. </returns> public override TypeMappingInfo WithBuiltInConverter(ValueConverterInfo converterInfo) => new RelationalTypeMappingInfo(this, converterInfo);
/// <summary> /// Returns a new <see cref="TypeMappingInfo" /> with the given converter applied. /// </summary> /// <param name="converterInfo"> The converter to apply. </param> /// <returns> The new mapping info. </returns> public RelationalTypeMappingInfo WithConverter(ValueConverterInfo converterInfo) => new RelationalTypeMappingInfo(this, converterInfo);
/// <summary> /// Returns a new <see cref="TypeMappingInfo" /> with the given converter applied. /// </summary> /// <param name="converterInfo"> The converter to apply. </param> /// <returns> The new mapping info. </returns> public TypeMappingInfo WithConverter(ValueConverterInfo converterInfo) => new TypeMappingInfo(this, converterInfo);
/// <summary> /// Returns a new <see cref="TypeMappingInfo" /> with the given converter applied. /// </summary> /// <param name="converterInfo"> The converter to apply. </param> /// <returns> The new mapping info. </returns> public virtual TypeMappingInfo WithBuiltInConverter(ValueConverterInfo converterInfo) => new TypeMappingInfo(this, converterInfo);