Exemple #1
0
        /// <summary>
        ///     Configures the property so that the property value is converted to and from the database
        ///     using the given <see cref="ValueConverter" />.
        /// </summary>
        /// <param name="converter"> The converter to use. </param>
        /// <param name="valueComparer"> The comparer to use for values before conversion. </param>
        /// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
        public virtual PropertyBuilder HasConversion(ValueConverter?converter, ValueComparer?valueComparer)
        {
            Builder.HasConversion(converter, ConfigurationSource.Explicit);
            Builder.HasValueComparer(valueComparer, ConfigurationSource.Explicit);

            return(this);
        }
Exemple #2
0
        protected CoreTypeMapping(CoreTypeMappingParameters parameters)
        {
            Parameters = parameters;

            var converter = parameters.Converter;

            var clrType = converter?.ModelClrType ?? parameters.ClrType;

            ClrType = clrType;

            if (parameters.Comparer?.Type == clrType)
            {
                _comparer = parameters.Comparer;
            }

            if (parameters.KeyComparer?.Type == clrType)
            {
                _keyComparer = parameters.KeyComparer;
            }

            if (parameters.StructuralComparer?.Type == clrType)
            {
                _structuralComparer = parameters.StructuralComparer;
            }

            ValueGeneratorFactory = parameters.ValueGeneratorFactory
                                    ?? converter?.MappingHints?.ValueGeneratorFactory;
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="CoreTypeMapping" /> class.
        /// </summary>
        /// <param name="parameters">The parameters for this mapping.</param>
        protected CoreTypeMapping(CoreTypeMappingParameters parameters)
        {
            Parameters = parameters;

            var converter = parameters.Converter;

            var clrType = converter?.ModelClrType ?? parameters.ClrType;

            ClrType = clrType;

            Check.DebugAssert(
                parameters.Comparer == null ||
                parameters.ClrType == null ||
                converter != null ||
                parameters.Comparer.Type == parameters.ClrType,
                $"Expected {parameters.ClrType}, got {parameters.Comparer?.Type}");
            if (parameters.Comparer?.Type == clrType)
            {
                _comparer = parameters.Comparer;
            }

            Check.DebugAssert(
                parameters.KeyComparer == null ||
                parameters.ClrType == null ||
                converter != null ||
                parameters.KeyComparer.Type == parameters.ClrType,
                $"Expected {parameters.ClrType}, got {parameters.KeyComparer?.Type}");
            if (parameters.KeyComparer?.Type == clrType)
            {
                _keyComparer = parameters.KeyComparer;
            }

            ValueGeneratorFactory = parameters.ValueGeneratorFactory
                                    ?? converter?.MappingHints?.ValueGeneratorFactory;
        }
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public SqlServerUdtTypeMapping(
            Type clrType,
            string storeType,
            Func <object, Expression> literalGenerator,
            StoreTypePostfix storeTypePostfix = StoreTypePostfix.None,
            string?udtTypeName        = null,
            ValueConverter?converter  = null,
            ValueComparer?comparer    = null,
            ValueComparer?keyComparer = null,
            DbType?dbType             = null,
            bool unicode     = false,
            int?size         = null,
            bool fixedLength = false,
            int?precision    = null,
            int?scale        = null)
            : base(
                new RelationalTypeMappingParameters(
                    new CoreTypeMappingParameters(
                        clrType, converter, comparer, keyComparer), storeType, storeTypePostfix, dbType, unicode, size, fixedLength,
                    precision, scale))

        {
            LiteralGenerator = literalGenerator;
            UdtTypeName      = udtTypeName ?? storeType;
        }
Exemple #5
0
        /// <summary>
        ///     Configures the property so that the property value is converted to the given type before
        ///     writing to the database and converted back when reading from the database.
        /// </summary>
        /// <param name="providerClrType"> The type to convert to and from. </param>
        /// <param name="valueComparer"> The comparer to use for values before conversion. </param>
        /// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
        public virtual PropertyBuilder HasConversion(Type?providerClrType, ValueComparer?valueComparer)
        {
            Builder.HasConversion(providerClrType, ConfigurationSource.Explicit);
            Builder.HasValueComparer(valueComparer, ConfigurationSource.Explicit);

            return(this);
        }
Exemple #6
0
        public SlimProperty(
            string name,
            Type clrType,
            PropertyInfo?propertyInfo,
            FieldInfo?fieldInfo,
            SlimEntityType declaringEntityType,
            PropertyAccessMode propertyAccessMode,
            bool nullable,
            bool concurrencyToken,
            ValueGenerated valueGenerated,
            PropertySaveBehavior beforeSaveBehavior,
            PropertySaveBehavior afterSaveBehavior,
            int?maxLength,
            bool?unicode,
            int?precision,
            int?scale,
            Type?providerClrType,
            Func <IProperty, IEntityType, ValueGenerator>?valueGeneratorFactory,
            ValueConverter?valueConverter,
            ValueComparer?valueComparer,
            ValueComparer?keyValueComparer,
            CoreTypeMapping?typeMapping)
            : base(name, propertyInfo, fieldInfo, propertyAccessMode)
        {
            DeclaringEntityType    = declaringEntityType;
            ClrType                = clrType;
            _isNullable            = nullable;
            _isConcurrencyToken    = concurrencyToken;
            _valueGenerated        = valueGenerated;
            _beforeSaveBehavior    = beforeSaveBehavior;
            _afterSaveBehavior     = afterSaveBehavior;
            _valueGeneratorFactory = valueGeneratorFactory;
            _valueConverter        = valueConverter;

            if (maxLength != null)
            {
                SetAnnotation(CoreAnnotationNames.MaxLength, maxLength);
            }
            if (unicode != null)
            {
                SetAnnotation(CoreAnnotationNames.Unicode, unicode);
            }
            if (precision != null)
            {
                SetAnnotation(CoreAnnotationNames.Precision, precision);
            }
            if (scale != null)
            {
                SetAnnotation(CoreAnnotationNames.Scale, scale);
            }
            if (providerClrType != null)
            {
                SetAnnotation(CoreAnnotationNames.ProviderClrType, providerClrType);
            }

            _typeMapping      = typeMapping;
            _valueComparer    = valueComparer ?? TypeMapping.Comparer;
            _keyValueComparer = keyValueComparer ?? TypeMapping.KeyComparer;
        }
Exemple #7
0
 public CoreTypeMappingParameters(
     [NotNull] Type clrType,
     [CanBeNull] ValueConverter?converter  = null,
     [CanBeNull] ValueComparer?comparer    = null,
     [CanBeNull] ValueComparer?keyComparer = null,
     [CanBeNull] Func <IProperty, IEntityType, ValueGenerator>?valueGeneratorFactory = null)
     : this(clrType, converter, comparer, keyComparer, null, valueGeneratorFactory)
 {
 }
Exemple #8
0
 /// <summary>
 ///     Configures the property so that the property value is converted to and from the database
 ///     using the given conversion expressions.
 /// </summary>
 /// <typeparam name="TProvider">The store type generated by the conversions.</typeparam>
 /// <param name="convertToProviderExpression">An expression to convert objects when writing data to the store.</param>
 /// <param name="convertFromProviderExpression">An expression to convert objects when reading data from the store.</param>
 /// <param name="valueComparer">The comparer to use for values before conversion.</param>
 /// <returns>The same builder instance so that multiple configuration calls can be chained.</returns>
 public virtual PropertyBuilder <TProperty> HasConversion <TProvider>(
     Expression <Func <TProperty, TProvider> > convertToProviderExpression,
     Expression <Func <TProvider, TProperty> > convertFromProviderExpression,
     ValueComparer?valueComparer)
 => HasConversion(
     new ValueConverter <TProperty, TProvider>(
         Check.NotNull(convertToProviderExpression, nameof(convertToProviderExpression)),
         Check.NotNull(convertFromProviderExpression, nameof(convertFromProviderExpression))),
     valueComparer);
Exemple #9
0
        /// <summary>
        ///     Configures the property so that the property value is converted to the given type before
        ///     writing to the database and converted back when reading from the database.
        /// </summary>
        /// <param name="providerClrType"> The type to convert to and from. </param>
        /// <param name="valueComparer"> The comparer to use for values before conversion. </param>
        /// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
        public virtual PropertyBuilder HasConversion(Type providerClrType, ValueComparer?valueComparer)
        {
            Check.NotNull(providerClrType, nameof(providerClrType));

            Builder.HasConversion(providerClrType, ConfigurationSource.Explicit);
            Builder.HasValueComparer(valueComparer, ConfigurationSource.Explicit);

            return(this);
        }
Exemple #10
0
 public CosmosTypeMapping(
     [NotNull] Type clrType,
     [CanBeNull] ValueComparer?comparer    = null,
     [CanBeNull] ValueComparer?keyComparer = null)
     : base(
         new CoreTypeMappingParameters(
             clrType,
             converter: null,
             comparer,
             keyComparer))
 {
 }
Exemple #11
0
 /// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 public CosmosTypeMapping(
     Type clrType,
     ValueComparer?comparer    = null,
     ValueComparer?keyComparer = null)
     : base(
         new CoreTypeMappingParameters(
             clrType,
             converter: null,
             comparer,
             keyComparer))
 {
 }
 /// <summary>
 ///     Creates a new <see cref="CoreTypeMappingParameters" /> parameter object.
 /// </summary>
 /// <param name="clrType">The .NET type used in the EF model.</param>
 /// <param name="converter">Converts types to and from the store whenever this mapping is used.</param>
 /// <param name="comparer">Supports custom value snapshotting and comparisons.</param>
 /// <param name="keyComparer">Supports custom comparisons between keys--e.g. PK to FK comparison.</param>
 /// <param name="valueGeneratorFactory">An optional factory for creating a specific <see cref="ValueGenerator" />.</param>
 public CoreTypeMappingParameters(
     Type clrType,
     ValueConverter?converter  = null,
     ValueComparer?comparer    = null,
     ValueComparer?keyComparer = null,
     Func <IProperty, IEntityType, ValueGenerator>?valueGeneratorFactory = null)
 {
     ClrType               = clrType;
     Converter             = converter;
     Comparer              = comparer;
     KeyComparer           = keyComparer;
     ValueGeneratorFactory = valueGeneratorFactory;
 }
            public CoreTypeMappingParameters(
                [NotNull] Type clrType,
                [CanBeNull] ValueConverter?converter  = null,
                [CanBeNull] ValueComparer?comparer    = null,
                [CanBeNull] ValueComparer?keyComparer = null,
                [CanBeNull] Func <IProperty, IEntityType, ValueGenerator>?valueGeneratorFactory = null)
            {
                Check.NotNull(clrType, nameof(clrType));

                ClrType               = clrType;
                Converter             = converter;
                Comparer              = comparer;
                KeyComparer           = keyComparer;
                ValueGeneratorFactory = valueGeneratorFactory;
            }
Exemple #14
0
            public CoreTypeMappingParameters(
                Type clrType,
                ValueConverter?converter,
                ValueComparer?comparer,
                ValueComparer?keyComparer,
                ValueComparer?structuralComparer,
                Func <IProperty, IEntityType, ValueGenerator>?valueGeneratorFactory)
            {
                Check.NotNull(clrType, nameof(clrType));

                ClrType               = clrType;
                Converter             = converter;
                Comparer              = comparer;
                KeyComparer           = keyComparer;
                ValueGeneratorFactory = valueGeneratorFactory;
            }
Exemple #15
0
        /// <summary>
        ///     Configures the property so that the property value is converted before
        ///     writing to the database and converted back when reading from the database.
        /// </summary>
        /// <param name="conversionType"> The type to convert to and from or a type that derives from <see cref="ValueConverter"/>. </param>
        /// <param name="valueComparer"> The comparer to use for values before conversion. </param>
        /// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
        public virtual PropertyBuilder HasConversion(Type conversionType, ValueComparer?valueComparer)
        {
            Check.NotNull(conversionType, nameof(conversionType));

            if (typeof(ValueConverter).IsAssignableFrom(conversionType))
            {
                Builder.HasConverter(conversionType, ConfigurationSource.Explicit);
            }
            else
            {
                Builder.HasConversion(conversionType, ConfigurationSource.Explicit);
            }

            Builder.HasValueComparer(valueComparer, ConfigurationSource.Explicit);

            return(this);
        }
Exemple #16
0
 /// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 public SqlServerByteArrayTypeMapping(
     string?storeType                  = null,
     int?size                          = null,
     bool fixedLength                  = false,
     ValueComparer?comparer            = null,
     SqlDbType?sqlDbType               = null,
     StoreTypePostfix?storeTypePostfix = null)
     : this(
         new RelationalTypeMappingParameters(
             new CoreTypeMappingParameters(typeof(byte[]), null, comparer),
             storeType ?? (fixedLength ? "binary" : "varbinary"),
             storeTypePostfix ?? StoreTypePostfix.Size,
             System.Data.DbType.Binary,
             size : size,
             fixedLength : fixedLength),
         sqlDbType)
 {
 }
 public static void SetKeyValueComparer([NotNull] this IMutableProperty property, [CanBeNull] ValueComparer?comparer)
 => property.AsProperty().SetValueComparer(comparer, ConfigurationSource.Explicit);
 public static void SetStructuralValueComparer(
     [NotNull] this IConventionProperty property,
     [CanBeNull] ValueComparer?comparer,
     bool fromDataAnnotation = false)
 => property.SetKeyValueComparer(comparer, fromDataAnnotation);
 public static void SetKeyValueComparer(
     [NotNull] this IConventionProperty property,
     [CanBeNull] ValueComparer?comparer,
     bool fromDataAnnotation = false)
 => property.AsProperty().SetValueComparer(
     comparer, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention);
Exemple #20
0
 public virtual PropertyBuilder HasConversion <TProvider>([CanBeNull] ValueComparer?valueComparer)
 => HasConversion(typeof(TProvider), valueComparer);
Exemple #21
0
 /// <summary>
 ///     Configures the property so that the property value is converted to and from the database
 ///     using the given <see cref="ValueConverter" />.
 /// </summary>
 /// <param name="converter">The converter to use.</param>
 /// <param name="valueComparer">The comparer to use for values before conversion.</param>
 /// <returns>The same builder instance so that multiple configuration calls can be chained.</returns>
 public new virtual PropertyBuilder <TProperty> HasConversion(
     ValueConverter?converter,
     ValueComparer?valueComparer)
 => (PropertyBuilder <TProperty>)base.HasConversion(converter, valueComparer);
Exemple #22
0
 /// <summary>
 ///     Configures the property so that the property value is converted to and from the database
 ///     using the given <see cref="ValueConverter{TModel,TProvider}" />.
 /// </summary>
 /// <typeparam name="TProvider">The store type generated by the converter.</typeparam>
 /// <param name="converter">The converter to use.</param>
 /// <param name="valueComparer">The comparer to use for values before conversion.</param>
 /// <returns>The same builder instance so that multiple configuration calls can be chained.</returns>
 public virtual PropertyBuilder <TProperty> HasConversion <TProvider>(
     ValueConverter <TProperty, TProvider>?converter,
     ValueComparer?valueComparer)
 => HasConversion((ValueConverter?)converter, valueComparer);
Exemple #23
0
 /// <summary>
 ///     Configures the property so that the property value is converted before
 ///     writing to the database and converted back when reading from the database.
 /// </summary>
 /// <typeparam name="TConversion">The type to convert to and from or a type that derives from <see cref="ValueConverter" />.</typeparam>
 /// <param name="valueComparer">The comparer to use for values before conversion.</param>
 /// <returns>The same builder instance so that multiple configuration calls can be chained.</returns>
 public new virtual PropertyBuilder <TProperty> HasConversion <TConversion>(ValueComparer?valueComparer)
 => (PropertyBuilder <TProperty>)base.HasConversion <TConversion>(valueComparer);
 public static void SetKeyValueComparer(
     this IConventionProperty property,
     ValueComparer?comparer,
     bool fromDataAnnotation = false)
 => property.SetValueComparer(comparer);
Exemple #25
0
 public static void SetStructuralValueComparer([NotNull] this IMutableProperty property, [CanBeNull] ValueComparer?comparer)
 => property.SetValueComparer(comparer);
Exemple #26
0
 public abstract TestPropertyBuilder <TProperty> HasConversion(ValueConverter?converter, ValueComparer?valueComparer);
 public static void SetStructuralValueComparer(this IMutableProperty property, ValueComparer?comparer)
 => property.SetValueComparer(comparer);
Exemple #28
0
 /// <summary>
 ///     Configures the property so that the property value is converted to the given type before
 ///     writing to the database and converted back when reading from the database.
 /// </summary>
 /// <param name="providerClrType"> The type to convert to and from. </param>
 /// <param name="valueComparer"> The comparer to use for values before conversion. </param>
 /// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
 public new virtual PropertyBuilder <TProperty> HasConversion(
     Type providerClrType,
     ValueComparer?valueComparer)
 => (PropertyBuilder <TProperty>)base.HasConversion(providerClrType, valueComparer);
Exemple #29
0
 /// <summary>
 ///     Configures the property so that the property value is converted before
 ///     writing to the database and converted back when reading from the database.
 /// </summary>
 /// <param name="valueComparer"> The comparer to use for values before conversion. </param>
 /// <typeparam name="TConversion"> The type to convert to and from or a type that derives from <see cref="ValueConverter"/>. </typeparam>
 /// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
 public virtual PropertyBuilder HasConversion <TConversion>(ValueComparer?valueComparer)
 => HasConversion(typeof(TConversion), valueComparer);
Exemple #30
0
 public new virtual PropertyBuilder <TProperty> HasConversion(
     [CanBeNull] Type?providerClrType,
     [CanBeNull] ValueComparer?valueComparer)
 => (PropertyBuilder <TProperty>)base.HasConversion(providerClrType, valueComparer);