Example #1
0
        public void GetMappingsEmptyTest()
        {
            var target = new TypeMappingInfo <TestClassA, TestClassC>();
            IEnumerable <MemberMappingInfo <TestClassA, TestClassC> > actual = target.GetMappings();

            Assert.IsFalse(actual.Any());
        }
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        protected override CoreTypeMapping FindMapping(TypeMappingInfo mappingInfo)
        {
            Check.NotNull(mappingInfo, nameof(mappingInfo));

            return(_typeMapper.IsTypeMapped(mappingInfo.ClrType)
                ? new ConcreteTypeMapping(mappingInfo.ClrType)
                : null);
        }
Example #3
0
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        protected override CoreTypeMapping FindMappingWithConversion(
            TypeMappingInfo mappingInfo,
            IProperty property)
        {
            _property = property;

            return(base.FindMappingWithConversion(mappingInfo, property));
        }
Example #4
0
 public void AddTest()
 {
     var m1 = new DelegateMappingInfo<TestClassE, TestClassB>("Prop1", "Prop2", (f, t) => { });
     var m2 = new DelegateMappingInfo<TestClassE, TestClassB>("Prop1", "Prop3", (f, t) => { });
     var target = new TypeMappingInfo<TestClassE, TestClassB>();
     target.Add(m1);
     target.Add(m2);
     Assert.IsTrue(target.GetMappings().Contains(m1));
     Assert.IsTrue(target.GetMappings().Contains(m2));
 }
Example #5
0
        public void AddTest()
        {
            var m1     = new DelegateMappingInfo <TestClassE, TestClassB>("Prop1", "Prop2", (f, t) => { });
            var m2     = new DelegateMappingInfo <TestClassE, TestClassB>("Prop1", "Prop3", (f, t) => { });
            var target = new TypeMappingInfo <TestClassE, TestClassB>();

            target.Add(m1);
            target.Add(m2);
            Assert.IsTrue(target.GetMappings().Contains(m1));
            Assert.IsTrue(target.GetMappings().Contains(m2));
        }
 /// <summary>
 ///     Creates a new instance of <see cref="RelationalTypeMappingInfo" />.
 /// </summary>
 /// <param name="storeTypeName">The provider-specific relational type name for which mapping is needed.</param>
 /// <param name="storeTypeNameBase">The provider-specific relational type name, with any facets removed.</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 RelationalTypeMappingInfo(
     string storeTypeName,
     string storeTypeNameBase,
     bool?unicode,
     int?size,
     int?precision,
     int?scale)
 {
     // Note: Empty string is allowed for store type name because SQLite
     _coreTypeMappingInfo = new TypeMappingInfo(null, false, unicode, size, null, precision, scale);
     StoreTypeName        = storeTypeName;
     StoreTypeNameBase    = storeTypeNameBase;
     IsFixedLength        = null;
 }
    /// <summary>
    ///     Creates a new instance of <see cref="RelationalTypeMappingInfo" />.
    /// </summary>
    /// <param name="member">The property or field for which mapping is needed.</param>
    /// <param name="storeTypeName">The provider-specific relational type name for which mapping is needed.</param>
    /// <param name="storeTypeNameBase">The provider-specific relational type name, with any facets removed.</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 RelationalTypeMappingInfo(
        MemberInfo member,
        string?storeTypeName     = null,
        string?storeTypeNameBase = null,
        bool?unicode             = null,
        int?size      = null,
        int?precision = null,
        int?scale     = null)
    {
        _coreTypeMappingInfo = new TypeMappingInfo(member, unicode, size, precision, scale);

        StoreTypeName     = storeTypeName;
        StoreTypeNameBase = storeTypeNameBase;
        IsFixedLength     = null;
    }
    /// <summary>
    ///     Creates a new instance of <see cref="RelationalTypeMappingInfo" />.
    /// </summary>
    /// <param name="principals">The principal property chain for the property for which mapping is needed.</param>
    /// <param name="storeTypeName">The provider-specific relational type name for which mapping is needed.</param>
    /// <param name="storeTypeNameBase">The provider-specific relational type name, with any facets removed.</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 <see langword="null" /> for default.
    /// </param>
    /// <param name="fixedLength">Specifies a fixed length mapping, or <see langword="null" /> for default.</param>
    /// <param name="fallbackSize">
    ///     Specifies a fallback size for the mapping, in case one isn't found at the core level, or <see langword="null" /> for
    ///     default.
    /// </param>
    /// <param name="fallbackPrecision">
    ///     Specifies a fallback precision for the mapping, in case one isn't found at the core level, or <see langword="null" />
    ///     for default.
    /// </param>
    /// <param name="fallbackScale">
    ///     Specifies a fallback scale for the mapping, in case one isn't found at the core level, or <see langword="null" /> for
    ///     default.
    /// </param>
    public RelationalTypeMappingInfo(
        IReadOnlyList <IProperty> principals,
        string?storeTypeName     = null,
        string?storeTypeNameBase = null,
        bool?fallbackUnicode     = null,
        bool?fixedLength         = null,
        int?fallbackSize         = null,
        int?fallbackPrecision    = null,
        int?fallbackScale        = null)
    {
        _coreTypeMappingInfo = new TypeMappingInfo(principals, fallbackUnicode, fallbackSize, fallbackPrecision, fallbackScale);

        IsFixedLength     = fixedLength;
        StoreTypeName     = storeTypeName;
        StoreTypeNameBase = storeTypeNameBase;
    }
Example #9
0
    /// <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();
    }
Example #10
0
        /// <summary>Initializes the internal mapping.</summary>
        private void InitializeMapping()
        {
            if (TypeMapping == null)
            {
                lock (_syncRoot)
                {
                    if (TypeMapping == null)
                    {
                        TypeMapping = new TypeMappingInfo <TSource, TTarget>();
                    }
                }
            }

            IEnumerable <MemberMappingInfo <TSource, TTarget> > mappings = GetMappings();

            if (mappings != null)
            {
                TypeMapping.AddRange(GetMappings());
            }

            TypeMapping.Compile();

            CurrentStatus = MapperStatus.Active;
        }
Example #11
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="CompositeMapper{TSource,TTarget}" /> class.
 /// </summary>
 /// <param name="constructionInfo">
 ///     Mapper construction information.
 /// </param>
 /// <param name="innerMappers">
 ///     The inner mappers.
 /// </param>
 public CompositeMapper(MapperConstructionInfo constructionInfo, params IMapper <TSource, TTarget>[] innerMappers)
     : base(constructionInfo)
 {
     Initialize(innerMappers);
     TypeMapping = new TypeMappingInfo <TSource, TTarget>(MappingOverwriteBehavior.SkipOverwrite);
 }
Example #12
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="CompositeMapper&lt;TSource, TTarget&gt;" /> class.
 /// </summary>
 /// <param name="innerMappers">The inner mappers.</param>
 public CompositeMapper(params IMapper <TSource, TTarget>[] innerMappers)
 {
     Initialize(innerMappers);
     TypeMapping = new TypeMappingInfo <TSource, TTarget>(MappingOverwriteBehavior.SkipOverwrite);
 }
Example #13
0
        private bool ValidateFieldMappings(TypeMapping typeMapping, Dictionary <TypeMapping, TypeMappingInfo> infoLookup)
        {
            TypeMappingInfo info = infoLookup.GetOrAdd(typeMapping, mapping => new TypeMappingInfo());

            try
            {
                // Quit validation if this type is already known to be invalid
                // and we have already thrown an appropriate exception
                if (info.HasError)
                {
                    throw new SuppressedValidationException();
                }

                // If a mapping's fields have already been fully traversed,
                // there is no need to traverse them again
                if (info.IsValid)
                {
                    return(info.HasBufferedDescendant);
                }

                // If a mapping has only been partially traversed,
                // then we must have arrived here via a circular reference
                if (info.Visited)
                {
                    RaiseCompileError($"Circular reference detected when validating type mapping '{typeMapping.Identifier}'.");
                }

                // Set visited flag to true to indicate
                // that we have begun field traversal
                info.Visited = true;

                foreach (FieldMapping fieldMapping in typeMapping.FieldMappings)
                {
                    DataType fieldType = fieldMapping.Field.Type;

                    // Make sure to check whether the field mapping
                    // is buffered before checking the base case
                    info.HasBufferedDescendant |= fieldMapping.IsBuffered;

                    // Base case: signal mappings do not
                    //            require additional validation
                    if (!fieldType.IsUserDefined)
                    {
                        continue;
                    }

                    if (fieldType.IsArray && !fieldMapping.IsBuffered)
                    {
                        // We know the field mapping is not buffered so we only need to check
                        // whether the referenced type mappings have buffered descendants
                        info.HasBufferedDescendant |= EnumerateTypeMappings(fieldMapping.Expression)
                                                      .Any(nestedMapping => ValidateFieldMappings(nestedMapping, infoLookup));
                    }
                    else
                    {
                        // Because we checked fieldMapping.IsBuffered at the beginning of the foreach loop,
                        // we do not need to check it again except to validate that there are no nested windows
                        if (ValidateFieldMappings(GetTypeMapping(fieldMapping.Expression), infoLookup))
                        {
                            if (fieldMapping.IsBuffered)
                            {
                                RaiseCompileError($"Nested window detected when validating field mapping '{typeMapping.Identifier}.{fieldMapping.Field.Identifier}'.");
                            }

                            // We know for sure that this type mapping has a buffered
                            // descendant if its referenced type mapping also has one
                            info.HasBufferedDescendant = true;
                        }
                    }
                }

                // Set is-valid flag to true to indicate
                // we have completed field traversal
                info.IsValid = true;

                return(info.HasBufferedDescendant);
            }
            catch
            {
                info.HasError = true;
                throw;
            }
        }
Example #14
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ManualMapper{TSource,TTarget}" /> class.
 /// </summary>
 /// <param name="constructionInfo">Mapper construction information.</param>
 public ManualMapper(MapperConstructionInfo constructionInfo)
     : base(constructionInfo)
 {
     TypeMapping = new TypeMappingInfo <TSource, TTarget>();
 }
Example #15
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ManualMapper{TSource,TTarget}" /> class.
 /// </summary>
 public ManualMapper()
 {
     TypeMapping = new TypeMappingInfo <TSource, TTarget>();
 }
Example #16
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="BaseMapper&lt;TSource, TTarget&gt;" /> class.
 /// </summary>
 protected BaseMapper()
 {
     TypeMapping = new TypeMappingInfo <TSource, TTarget>();
 }
Example #17
0
 public void GetMappingsEmptyTest()
 {
     var target = new TypeMappingInfo<TestClassA, TestClassC>();
     var actual = target.GetMappings();
     Assert.IsFalse(actual.Any());
 }