/// <summary>
 ///    Returns a new copy of this type mapping with the given <see cref="ValueConverter"/>
 ///    added.
 /// </summary>
 /// <param name="converter"> The converter to use. </param>
 /// <returns> A new type mapping </returns>
 public override CoreTypeMapping Clone(ValueConverter converter)
 => new IntTypeMapping(StoreType, ComposeConverter(converter), Comparer, KeyComparer, DbType);
 /// <summary>
 ///    Returns a new copy of this type mapping with the given <see cref="ValueConverter"/>
 ///    added.
 /// </summary>
 /// <param name="converter"> The converter to use. </param>
 /// <returns> A new type mapping </returns>
 public override CoreTypeMapping Clone(ValueConverter converter)
 => new DecimalTypeMapping(StoreType, ComposeConverter(converter), DbType);
Beispiel #3
0
 /// <summary>
 ///    Returns a new copy of this type mapping with the given <see cref="ValueConverter"/>
 ///    added.
 /// </summary>
 /// <param name="converter"> The converter to use. </param>
 /// <returns> A new type mapping </returns>
 public override CoreTypeMapping Clone(ValueConverter converter)
 => new BoolTypeMapping(Parameters.WithComposedConverter(converter));
 /// <summary>
 ///    Returns a new copy of this type mapping with the given <see cref="ValueConverter"/>
 ///    added.
 /// </summary>
 /// <param name="converter"> The converter to use. </param>
 /// <returns> A new type mapping </returns>
 public override CoreTypeMapping Clone(ValueConverter converter)
 => throw new NotImplementedException(CoreStrings.ConverterCloneNotImplemented(GetType().ShortDisplayName()));
 public override CoreTypeMapping Clone(ValueConverter converter)
 => this;
Beispiel #6
0
 /// <summary>
 ///     Returns a new copy of this type mapping with the given <see cref="ValueConverter" />
 ///     added.
 /// </summary>
 /// <param name="converter"> The converter to use. </param>
 /// <returns> A new type mapping </returns>
 public virtual CoreTypeMapping Clone([CanBeNull] ValueConverter converter)
 => new CoreTypeMapping(ClrType, ComposeConverter(converter));
Beispiel #7
0
 /// <summary>
 ///     Composes the given <see cref="ValueConverter" /> with any already in this mapping
 ///     and returns a new <see cref="ValueConverter" /> combining them together.
 /// </summary>
 /// <param name="converter"> The new converter. </param>
 /// <returns> The composed converter. </returns>
 protected virtual ValueConverter ComposeConverter([CanBeNull] ValueConverter converter)
 => converter == null ? Converter : converter.ComposeWith(Converter);
 /// <summary>
 ///    Returns a new copy of this type mapping with the given <see cref="ValueConverter"/>
 ///    added.
 /// </summary>
 /// <param name="converter"> The converter to use. </param>
 /// <returns> A new type mapping </returns>
 public override CoreTypeMapping Clone(ValueConverter converter)
 => new DateTimeOffsetTypeMapping(StoreType, ComposeConverter(converter), DbType);
 /// <summary>
 ///     Returns a new copy of this type mapping with the given <see cref="ValueConverter" />
 ///     added.
 /// </summary>
 /// <param name="converter"> The converter to use. </param>
 /// <returns> A new type mapping </returns>
 public abstract CoreTypeMapping Clone([CanBeNull] ValueConverter converter);
 /// <summary>
 ///    Returns a new copy of this type mapping with the given <see cref="ValueConverter"/>
 ///    added.
 /// </summary>
 /// <param name="converter"> The converter to use. </param>
 /// <returns> A new type mapping </returns>
 public override CoreTypeMapping Clone(ValueConverter converter)
 => new StringTypeMapping(StoreType, ComposeConverter(converter), DbType, IsUnicode, Size);
Beispiel #11
0
        /// <summary>
        ///     Creates a new instance of <see cref="TypeMappingInfo" />.
        /// </summary>
        /// <param name="principals"> The principal property chain for the property for which mapping is needed. </param>
        /// <param name="fallbackUnicode">
        ///     Specifies a fallback Specifies Unicode or ANSI mapping for the mapping, in case one isn't found at the core
        ///     level, or <c>null</c> for default.
        /// </param>
        /// <param name="fallbackSize">
        ///     Specifies a fallback size for the mapping, in case one isn't found at the core level, or <c>null</c> for
        ///     default.
        /// </param>
        /// <param name="fallbackPrecision">
        ///     Specifies a fallback precision for the mapping, in case one isn't found at the core level, or <c>null</c>
        ///     for default.
        /// </param>
        /// <param name="fallbackScale">
        ///     Specifies a fallback scale for the mapping, in case one isn't found at the core level, or <c>null</c> for
        ///     default.
        /// </param>
        public TypeMappingInfo(
            [NotNull] IReadOnlyList <IProperty> principals,
            bool?fallbackUnicode  = null,
            int?fallbackSize      = null,
            int?fallbackPrecision = null,
            int?fallbackScale     = null)
        {
            Check.NotNull(principals, nameof(principals));

            ValueConverter customConverter = null;
            int?           size            = null;
            int?           precision       = null;
            int?           scale           = null;
            bool?          isUnicode       = null;

            for (var i = 0; i < principals.Count; i++)
            {
                var principal = principals[i];
                if (customConverter == null)
                {
                    var converter = principal.GetValueConverter();
                    if (converter != null)
                    {
                        customConverter = converter;
                    }
                }

                if (size == null)
                {
                    var maxLength = principal.GetMaxLength();
                    if (maxLength != null)
                    {
                        size = maxLength;
                    }
                }

                if (precision == null)
                {
                    var precisionFromProperty = principal.GetPrecision();
                    if (precisionFromProperty != null)
                    {
                        precision = precisionFromProperty;
                    }
                }

                if (scale == null)
                {
                    var scaleFromProperty = principal.GetScale();
                    if (scaleFromProperty != null)
                    {
                        scale = scaleFromProperty;
                    }
                }

                if (isUnicode == null)
                {
                    var unicode = principal.IsUnicode();
                    if (unicode != null)
                    {
                        isUnicode = unicode;
                    }
                }
            }

            var mappingHints = customConverter?.MappingHints;
            var property     = principals[0];

            IsKeyOrIndex = property.IsKeyOrForeignKey() || property.IsIndex();
            Size         = size ?? mappingHints?.Size ?? fallbackSize;
            IsUnicode    = isUnicode ?? mappingHints?.IsUnicode ?? fallbackUnicode;
            IsRowVersion = property.IsConcurrencyToken && property.ValueGenerated == ValueGenerated.OnAddOrUpdate;
            ClrType      = (customConverter?.ProviderClrType ?? property.ClrType).UnwrapNullableType();
            Scale        = scale ?? mappingHints?.Scale ?? fallbackScale;
            Precision    = precision ?? mappingHints?.Precision ?? fallbackPrecision;
        }
Beispiel #12
0
 /// <summary>
 ///    Returns a new copy of this type mapping with the given <see cref="ValueConverter"/>
 ///    added.
 /// </summary>
 /// <param name="converter"> The converter to use. </param>
 /// <returns> A new type mapping </returns>
 public override CoreTypeMapping Clone(ValueConverter converter)
 => new ByteArrayTypeMapping(StoreType, ComposeConverter(converter), Comparer, DbType, Size, IsFixedLength);