Exemple #1
0
        protected virtual void Visit(EntityContainerMapping entityContainerMapping)
        {
            Visit(entityContainerMapping.EdmEntityContainer);
            Visit(entityContainerMapping.StorageEntityContainer);

            foreach (var mapping in GetSequence(entityContainerMapping.EntitySetMaps, it => IdentityHelper.GetIdentity(it)))
            {
                Visit(mapping);
            }
        }
        internal static string GetMappingClosureHash(
            double mappingVersion,
            EntityContainerMapping entityContainerMapping,
            bool sortSequence = true)
        {
            MetadataMappingHasherVisitor mappingHasherVisitor = new MetadataMappingHasherVisitor(mappingVersion, sortSequence);

            mappingHasherVisitor.Visit(entityContainerMapping);
            return(mappingHasherVisitor.HashValue);
        }
        public void Can_get_store_and_entity_containers()
        {
            var entityContainer        = new EntityContainer("C", DataSpace.CSpace);
            var storeContainer         = new EntityContainer("S", DataSpace.CSpace);
            var entityContainerMapping =
                new EntityContainerMapping(entityContainer, storeContainer, null, false, false);

            Assert.Same(entityContainer, entityContainerMapping.EdmEntityContainer);
            Assert.Same(storeContainer, entityContainerMapping.StorageEntityContainer);
        }
Exemple #4
0
        /// <summary>
        /// Initialiazes a new EntitySetMapping instance.
        /// </summary>
        /// <param name="entitySet">The entity set to be mapped.</param>
        /// <param name="containerMapping">The parent container mapping.</param>
        public EntitySetMapping(EntitySet entitySet, EntityContainerMapping containerMapping)
            : base(containerMapping)
        {
            Check.NotNull(entitySet, "entitySet");

            _entitySet                          = entitySet;
            _entityTypeMappings                 = new List <EntityTypeMapping>();
            _modificationFunctionMappings       = new List <EntityTypeModificationFunctionMapping>();
            _implicitlyMappedAssociationSetEnds = new Lazy <List <AssociationSetEnd> >(
                InitializeImplicitlyMappedAssociationSetEnds);
        }
Exemple #5
0
        /// <summary>
        /// Initializes a new FunctionImportMappingComposable instance.
        /// </summary>
        /// <param name="functionImport">The model function import.</param>
        /// <param name="targetFunction">The store composable function.</param>
        /// <param name="resultMapping">The result mapping for the function import.</param>
        /// <param name="containerMapping">The parent container mapping.</param>
        public FunctionImportMappingComposable(
            EdmFunction functionImport,
            EdmFunction targetFunction,
            FunctionImportResultMapping resultMapping,
            EntityContainerMapping containerMapping)
            : base(Check.NotNull <EdmFunction>(functionImport, nameof(functionImport)), Check.NotNull <EdmFunction>(targetFunction, nameof(targetFunction)))
        {
            Check.NotNull <FunctionImportResultMapping>(resultMapping, nameof(resultMapping));
            Check.NotNull <EntityContainerMapping>(containerMapping, nameof(containerMapping));
            if (!functionImport.IsComposableAttribute)
            {
                throw new ArgumentException(Strings.NonComposableFunctionCannotBeMappedAsComposable((object)nameof(functionImport)));
            }
            if (!targetFunction.IsComposableAttribute)
            {
                throw new ArgumentException(Strings.NonComposableFunctionCannotBeMappedAsComposable((object)nameof(targetFunction)));
            }
            EdmType returnType;

            if (!MetadataHelper.TryGetFunctionImportReturnType <EdmType>(functionImport, 0, out returnType))
            {
                throw new ArgumentException(Strings.InvalidReturnTypeForComposableFunction);
            }
            EdmFunction edmFunction = containerMapping.StorageMappingItemCollection != null?containerMapping.StorageMappingItemCollection.StoreItemCollection.ConvertToCTypeFunction(targetFunction) : StoreItemCollection.ConvertFunctionSignatureToCType(targetFunction);

            RowType tvfReturnType1 = TypeHelpers.GetTvfReturnType(edmFunction);
            RowType tvfReturnType2 = TypeHelpers.GetTvfReturnType(targetFunction);

            if (tvfReturnType1 == null)
            {
                throw new ArgumentException(Strings.Mapping_FunctionImport_ResultMapping_InvalidSType((object)functionImport.Identity), nameof(functionImport));
            }
            List <EdmSchemaError> parsingErrors = new List <EdmSchemaError>();
            FunctionImportMappingComposableHelper composableHelper = new FunctionImportMappingComposableHelper(containerMapping, string.Empty, parsingErrors);
            FunctionImportMappingComposable       mapping;

            if (Helper.IsStructuralType(returnType))
            {
                composableHelper.TryCreateFunctionImportMappingComposableWithStructuralResult(functionImport, edmFunction, resultMapping.SourceList, tvfReturnType1, tvfReturnType2, (IXmlLineInfo)LineInfo.Empty, out mapping);
            }
            else
            {
                composableHelper.TryCreateFunctionImportMappingComposableWithScalarResult(functionImport, edmFunction, targetFunction, returnType, tvfReturnType1, (IXmlLineInfo)LineInfo.Empty, out mapping);
            }
            if (mapping == null)
            {
                throw new InvalidOperationException(parsingErrors.Count > 0 ? parsingErrors[0].Message : string.Empty);
            }
            this._containerMapping        = mapping._containerMapping;
            this.m_commandParameters      = mapping.m_commandParameters;
            this.m_structuralTypeMappings = mapping.m_structuralTypeMappings;
            this.m_targetFunctionKeys     = mapping.m_targetFunctionKeys;
            this._resultMapping           = resultMapping;
        }
 /// <summary>Initializes a new AssociationSetMapping instance.</summary>
 /// <param name="associationSet">The association set to be mapped.</param>
 /// <param name="storeEntitySet">The store entity set to be mapped.</param>
 /// <param name="containerMapping">The parent container mapping.</param>
 public AssociationSetMapping(
     AssociationSet associationSet,
     EntitySet storeEntitySet,
     EntityContainerMapping containerMapping)
     : base(containerMapping)
 {
     Check.NotNull <AssociationSet>(associationSet, nameof(associationSet));
     Check.NotNull <EntitySet>(storeEntitySet, nameof(storeEntitySet));
     this._associationSet         = associationSet;
     this._associationTypeMapping = new AssociationTypeMapping(associationSet.ElementType, this);
     this._associationTypeMapping.MappingFragment = new MappingFragment(storeEntitySet, (TypeMapping)this._associationTypeMapping, false);
 }
Exemple #7
0
        public void Cannot_add_type_mapping_when_read_only()
        {
            var entityContainerMapping = new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace));
            var entitySetMapping       = new EntitySetMapping(new EntitySet(), entityContainerMapping);
            var entityTypeMapping      = new EntityTypeMapping(entitySetMapping);

            entitySetMapping.SetReadOnly();

            Assert.Equal(
                Strings.OperationOnReadOnlyItem,
                Assert.Throws <InvalidOperationException>(
                    () => entitySetMapping.AddTypeMapping(entityTypeMapping)).Message);
        }
Exemple #8
0
 internal FunctionImportMappingComposable(
     EdmFunction functionImport,
     EdmFunction targetFunction,
     List <Tuple <StructuralType, List <ConditionPropertyMapping>, List <PropertyMapping> > > structuralTypeMappings,
     EdmProperty[] targetFunctionKeys,
     EntityContainerMapping containerMapping)
     : base(functionImport, targetFunction)
 {
     this._containerMapping        = containerMapping;
     this.m_commandParameters      = functionImport.Parameters.Select <FunctionParameter, DbParameterReferenceExpression>((Func <FunctionParameter, DbParameterReferenceExpression>)(p => TypeHelpers.GetPrimitiveTypeUsageForScalar(p.TypeUsage).Parameter(p.Name))).ToArray <DbParameterReferenceExpression>();
     this.m_structuralTypeMappings = structuralTypeMappings;
     this.m_targetFunctionKeys     = targetFunctionKeys;
 }
        /// <summary>
        /// Initializes a new FunctionImportMappingNonComposable instance.
        /// </summary>
        /// <param name="functionImport">The model function import.</param>
        /// <param name="targetFunction">The store non-composable function.</param>
        /// <param name="resultMappings">The function import result mappings.</param>
        /// <param name="containerMapping">The parent container mapping.</param>
        public FunctionImportMappingNonComposable(
            EdmFunction functionImport,
            EdmFunction targetFunction,
            IEnumerable <FunctionImportResultMapping> resultMappings,
            EntityContainerMapping containerMapping)
            : base(
                Check.NotNull(functionImport, "functionImport"),
                Check.NotNull(targetFunction, "targetFunction"))
        {
            Check.NotNull(resultMappings, "resultMappings");
            Check.NotNull(containerMapping, "containerMapping");

            Debug.Assert(!functionImport.IsComposableAttribute);
            Debug.Assert(!targetFunction.IsComposableAttribute);


            if (!resultMappings.Any())
            {
                // when this method is invoked when a CodeFirst model is being built (e.g. from a custom convention) the
                // StorageMappingItemCollection will be null. In this case we can provide an empty EdmItemCollection which
                // will allow inferring implicit result mapping
                var edmItemCollection = containerMapping.StorageMappingItemCollection != null
                    ? containerMapping.StorageMappingItemCollection.EdmItemCollection
                    : new EdmItemCollection(new EdmModel(DataSpace.CSpace));

                _internalResultMappings = new ReadOnlyCollection <FunctionImportStructuralTypeMappingKB>(
                    new[]
                {
                    new FunctionImportStructuralTypeMappingKB(
                        new List <FunctionImportStructuralTypeMapping>(),
                        edmItemCollection)
                });
                noExplicitResultMappings = true;
            }
            else
            {
                Debug.Assert(functionImport.ReturnParameters.Count == resultMappings.Count());

                _internalResultMappings = new ReadOnlyCollection <FunctionImportStructuralTypeMappingKB>(
                    resultMappings
                    .Select(
                        resultMapping => new FunctionImportStructuralTypeMappingKB(
                            resultMapping.TypeMappings,
                            containerMapping.StorageMappingItemCollection.EdmItemCollection))
                    .ToArray());

                noExplicitResultMappings = false;
            }

            _resultMappings = new ReadOnlyCollection <FunctionImportResultMapping>(resultMappings.ToList());
        }
Exemple #10
0
        public void Can_get_entity_type_mappings()
        {
            var entityContainerMapping = new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace));
            var entitySetMapping       = new EntitySetMapping(new EntitySet(), entityContainerMapping);

            Assert.Empty(entitySetMapping.EntityTypeMappings);

            var entityTypeMapping
                = new EntityTypeMapping(
                      new EntitySetMapping(new EntitySet(), entityContainerMapping));

            entitySetMapping.AddTypeMapping(entityTypeMapping);

            Assert.Same(entityTypeMapping, entitySetMapping.EntityTypeMappings.Single());
        }
Exemple #11
0
        public void Can_get_association_set_mappings()
        {
            var entityContainerMapping = new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace));

            Assert.Empty(entityContainerMapping.AssociationSetMappings);
            Assert.Empty(entityContainerMapping.RelationshipSetMaps);

            var associationSetMapping
                = new AssociationSetMapping(
                      new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)), entityContainerMapping);

            entityContainerMapping.AddSetMapping(associationSetMapping);

            Assert.Same(associationSetMapping, entityContainerMapping.AssociationSetMappings.Single());
            Assert.Same(associationSetMapping, entityContainerMapping.RelationshipSetMaps.Single());
        }
Exemple #12
0
        public void Can_get_entity_set_mappings()
        {
            var entityContainerMapping = new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace));

            Assert.Empty(entityContainerMapping.EntitySetMappings);
            Assert.Empty(entityContainerMapping.EntitySetMaps);

            var entitySetMapping
                = new EntitySetMapping(
                      new EntitySet("ES", null, null, null, new EntityType("E", "N", DataSpace.CSpace)), entityContainerMapping);

            entityContainerMapping.AddSetMapping(entitySetMapping);

            Assert.Same(entitySetMapping, entityContainerMapping.EntitySetMappings.Single());
            Assert.Same(entitySetMapping, entityContainerMapping.EntitySetMaps.Single());
        }
Exemple #13
0
        public void Can_add_and_get_function_import_mapping()
        {
            var typeUsage =
                TypeUsage.CreateDefaultTypeUsage(
                    PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32).GetCollectionType());

            var entityContainerMapping = new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace));

            var composableFunctionMapping =
                new FunctionImportMappingComposable(
                    new EdmFunction(
                        "f", "model", DataSpace.CSpace,
                        new EdmFunctionPayload()
            {
                IsComposable     = true,
                ReturnParameters =
                    new[]
                {
                    new FunctionParameter(
                        "ReturnType",
                        typeUsage,
                        ParameterMode.ReturnValue),
                }
            }),
                    new EdmFunction(
                        "f", "store", DataSpace.SSpace,
                        new EdmFunctionPayload()
            {
                IsComposable     = true,
                ReturnParameters =
                    new[]
                {
                    new FunctionParameter(
                        "ReturnType",
                        typeUsage,
                        ParameterMode.ReturnValue),
                }
            }),
                    null);

            Assert.Empty(entityContainerMapping.FunctionImportMappings);
            entityContainerMapping.AddFunctionImportMapping(composableFunctionMapping);
            Assert.Same(composableFunctionMapping, entityContainerMapping.FunctionImportMappings.Single());
        }
        /// <summary>
        /// Initializes a new FunctionImportMappingNonComposable instance.
        /// </summary>
        /// <param name="functionImport">The model function import.</param>
        /// <param name="targetFunction">The store non-composable function.</param>
        /// <param name="resultMappings">The function import result mappings.</param>
        /// <param name="containerMapping">The parent container mapping.</param>
        public FunctionImportMappingNonComposable(
            EdmFunction functionImport,
            EdmFunction targetFunction,
            IEnumerable <FunctionImportResultMapping> resultMappings,
            EntityContainerMapping containerMapping)
            : base(
                Check.NotNull(functionImport, "functionImport"),
                Check.NotNull(targetFunction, "targetFunction"))
        {
            Check.NotNull(resultMappings, "resultMappings");
            Check.NotNull(containerMapping, "containerMapping");

            Debug.Assert(!functionImport.IsComposableAttribute);
            Debug.Assert(!targetFunction.IsComposableAttribute);

            if (!resultMappings.Any())
            {
                _internalResultMappings = new ReadOnlyCollection <FunctionImportStructuralTypeMappingKB>(
                    new[]
                {
                    new FunctionImportStructuralTypeMappingKB(
                        new List <FunctionImportStructuralTypeMapping>(),
                        containerMapping.StorageMappingItemCollection.EdmItemCollection)
                });
                noExplicitResultMappings = true;
            }
            else
            {
                Debug.Assert(functionImport.ReturnParameters.Count == resultMappings.Count());

                _internalResultMappings = new ReadOnlyCollection <FunctionImportStructuralTypeMappingKB>(
                    resultMappings
                    .Select(
                        resultMapping => new FunctionImportStructuralTypeMappingKB(
                            resultMapping.TypeMappings,
                            containerMapping.StorageMappingItemCollection.EdmItemCollection))
                    .ToArray());

                noExplicitResultMappings = false;
            }

            _resultMappings = new ReadOnlyCollection <FunctionImportResultMapping>(resultMappings.ToList());
        }
        protected override void Visit(EntityContainerMapping entityContainerMapping)
        {
            DebugCheck.NotNull(entityContainerMapping);

            // at the entry point of visitor, we setup the versions
            Debug.Assert(
                m_MappingVersion == entityContainerMapping.StorageMappingItemCollection.MappingVersion,
                "the original version and the mapping collection version are not the same");
            m_MappingVersion = entityContainerMapping.StorageMappingItemCollection.MappingVersion;

            m_EdmItemCollection = entityContainerMapping.StorageMappingItemCollection.EdmItemCollection;

            int index;

            if (!AddObjectToSeenListAndHashBuilder(entityContainerMapping, out index))
            {
                // if this has been add to the seen list, then just
                return;
            }
            if (m_itemsAlreadySeen.Count > 1)
            {
                // this means user try another visit over SECM, this is allowed but all the previous visit all lost due to clean
                // user can visit different SECM objects by using the same visitor to load the SECM object
                Clean();
                Visit(entityContainerMapping);
                return;
            }

            AddObjectStartDumpToHashBuilder(entityContainerMapping, index);

            #region Inner data visit

            AddObjectContentToHashBuilder(entityContainerMapping.Identity);

            AddV2ObjectContentToHashBuilder(entityContainerMapping.GenerateUpdateViews, m_MappingVersion);

            base.Visit(entityContainerMapping);

            #endregion

            AddObjectEndDumpToHashBuilder();
        }
Exemple #16
0
        public void SetReadOnly_is_called_on_child_mapping_items()
        {
            var conceptualContainer = new EntityContainer("C", DataSpace.CSpace);
            var storeContainer      = new EntityContainer("S", DataSpace.CSpace);
            var containerMapping    = new EntityContainerMapping(conceptualContainer, storeContainer, null, false);

            var entitySet
                = new EntitySet(
                      "ES", "S", "T", "Q",
                      new EntityType("ET", "N", DataSpace.SSpace));
            var entitySetMapping = new EntitySetMapping(entitySet, containerMapping);
            var associationSetMapping
                = new AssociationSetMapping(
                      new AssociationSet(
                          "AS",
                          new AssociationType("AT", "N", false, DataSpace.CSpace)),
                      entitySet);
            var functionImportMapping
                = new FunctionImportMappingFake(
                      new EdmFunction("FI", "N", DataSpace.CSpace),
                      new EdmFunction("TF", "N", DataSpace.SSpace));

            containerMapping.AddSetMapping(entitySetMapping);
            containerMapping.AddSetMapping(associationSetMapping);
            containerMapping.AddFunctionImportMapping(functionImportMapping);

            Assert.False(containerMapping.IsReadOnly);
            Assert.False(entitySetMapping.IsReadOnly);
            Assert.False(associationSetMapping.IsReadOnly);
            Assert.False(functionImportMapping.IsReadOnly);

            containerMapping.SetReadOnly();

            Assert.True(containerMapping.IsReadOnly);
            Assert.True(entitySetMapping.IsReadOnly);
            Assert.True(associationSetMapping.IsReadOnly);
            Assert.True(functionImportMapping.IsReadOnly);
        }
        protected override void Visit(EntityContainerMapping entityContainerMapping)
        {
            this.m_MappingVersion    = entityContainerMapping.StorageMappingItemCollection.MappingVersion;
            this.m_EdmItemCollection = entityContainerMapping.StorageMappingItemCollection.EdmItemCollection;
            int instanceIndex;

            if (!this.AddObjectToSeenListAndHashBuilder((object)entityContainerMapping, out instanceIndex))
            {
                return;
            }
            if (this.m_itemsAlreadySeen.Count > 1)
            {
                this.Clean();
                this.Visit(entityContainerMapping);
            }
            else
            {
                this.AddObjectStartDumpToHashBuilder((object)entityContainerMapping, instanceIndex);
                this.AddObjectContentToHashBuilder((object)entityContainerMapping.Identity);
                this.AddV2ObjectContentToHashBuilder((object)entityContainerMapping.GenerateUpdateViews, this.m_MappingVersion);
                base.Visit(entityContainerMapping);
                this.AddObjectEndDumpToHashBuilder();
            }
        }
Exemple #18
0
 /// <summary>
 /// Initializes a new FunctionImportMappingNonComposable instance.
 /// </summary>
 /// <param name="functionImport">The model function import.</param>
 /// <param name="targetFunction">The store non-composable function.</param>
 /// <param name="resultMappings">The function import result mappings.</param>
 /// <param name="containerMapping">The parent container mapping.</param>
 public FunctionImportMappingNonComposable(
     EdmFunction functionImport,
     EdmFunction targetFunction,
     IEnumerable <FunctionImportResultMapping> resultMappings,
     EntityContainerMapping containerMapping)
     : base(Check.NotNull <EdmFunction>(functionImport, nameof(functionImport)), Check.NotNull <EdmFunction>(targetFunction, nameof(targetFunction)))
 {
     Check.NotNull <IEnumerable <FunctionImportResultMapping> >(resultMappings, nameof(resultMappings));
     Check.NotNull <EntityContainerMapping>(containerMapping, nameof(containerMapping));
     if (!resultMappings.Any <FunctionImportResultMapping>())
     {
         this._internalResultMappings = new ReadOnlyCollection <FunctionImportStructuralTypeMappingKB>((IList <FunctionImportStructuralTypeMappingKB>) new FunctionImportStructuralTypeMappingKB[1]
         {
             new FunctionImportStructuralTypeMappingKB((IEnumerable <FunctionImportStructuralTypeMapping>) new List <FunctionImportStructuralTypeMapping>(), (ItemCollection)(containerMapping.StorageMappingItemCollection != null ? containerMapping.StorageMappingItemCollection.EdmItemCollection : new EdmItemCollection(new EdmModel(DataSpace.CSpace, 3.0))))
         });
         this.noExplicitResultMappings = true;
     }
     else
     {
         this._internalResultMappings  = new ReadOnlyCollection <FunctionImportStructuralTypeMappingKB>((IList <FunctionImportStructuralTypeMappingKB>)resultMappings.Select <FunctionImportResultMapping, FunctionImportStructuralTypeMappingKB>((Func <FunctionImportResultMapping, FunctionImportStructuralTypeMappingKB>)(resultMapping => new FunctionImportStructuralTypeMappingKB((IEnumerable <FunctionImportStructuralTypeMapping>)resultMapping.TypeMappings, (ItemCollection)containerMapping.StorageMappingItemCollection.EdmItemCollection))).ToArray <FunctionImportStructuralTypeMappingKB>());
         this.noExplicitResultMappings = false;
     }
     this._resultMappings = new ReadOnlyCollection <FunctionImportResultMapping>((IList <FunctionImportResultMapping>)resultMappings.ToList <FunctionImportResultMapping>());
 }
 internal EntitySetBaseMapping(EntityContainerMapping containerMapping)
 {
     this._containerMapping = containerMapping;
 }
        /// <summary>
        /// Initializes a new FunctionImportMappingComposable instance.
        /// </summary>
        /// <param name="functionImport">The model function import.</param>
        /// <param name="targetFunction">The store composable function.</param>
        /// <param name="resultMapping">The result mapping for the function import.</param>
        /// <param name="containerMapping">The parent container mapping.</param>
        public FunctionImportMappingComposable(
            EdmFunction functionImport,
            EdmFunction targetFunction,
            FunctionImportResultMapping resultMapping,
            EntityContainerMapping containerMapping)
            : base(
                Check.NotNull(functionImport, "functionImport"),
                Check.NotNull(targetFunction, "targetFunction"))
        {
            Check.NotNull(resultMapping, "resultMapping");
            Check.NotNull(containerMapping, "containerMapping");

            if (!functionImport.IsComposableAttribute)
            {
                throw new ArgumentException(Strings.NonComposableFunctionCannotBeMappedAsComposable("functionImport"));
            }

            if (!targetFunction.IsComposableAttribute)
            {
                throw new ArgumentException(Strings.NonComposableFunctionCannotBeMappedAsComposable("targetFunction"));
            }

            EdmType resultType;

            if (!MetadataHelper.TryGetFunctionImportReturnType(functionImport, 0, out resultType))
            {
                throw new ArgumentException(Strings.InvalidReturnTypeForComposableFunction);
            }

            // when this method is invoked when a CodeFirst model is being built (e.g. from a custom convention) the
            // StorageMappingItemCollection will be null. In this case we can call the converting method directly which
            // will return the correct result but the result won't be memoized. This however does not matter at this
            // point since the model is still being constructed.
            var cTypeTargetFunction =
                containerMapping.StorageMappingItemCollection != null
                ? containerMapping.StorageMappingItemCollection.StoreItemCollection.ConvertToCTypeFunction(targetFunction)
                : StoreItemCollection.ConvertFunctionSignatureToCType(targetFunction);

            var cTypeTvfElementType = TypeHelpers.GetTvfReturnType(cTypeTargetFunction);
            var sTypeTvfElementType = TypeHelpers.GetTvfReturnType(targetFunction);

            if (cTypeTvfElementType == null)
            {
                Debug.Assert(sTypeTvfElementType == null);

                throw new ArgumentException(
                          Strings.Mapping_FunctionImport_ResultMapping_InvalidSType(functionImport.Identity),
                          "functionImport");
            }

            var errors = new List <EdmSchemaError>();
            var functionImportHelper = new FunctionImportMappingComposableHelper(
                containerMapping,
                String.Empty,
                errors);

            FunctionImportMappingComposable mapping;

            if (Helper.IsStructuralType(resultType))
            {
                functionImportHelper.TryCreateFunctionImportMappingComposableWithStructuralResult(
                    functionImport,
                    cTypeTargetFunction,
                    resultMapping.SourceList,
                    cTypeTvfElementType,
                    sTypeTvfElementType,
                    LineInfo.Empty,
                    out mapping);
            }
            else
            {
                Debug.Assert(TypeSemantics.IsScalarType(resultType));
                Debug.Assert(resultMapping.TypeMappings.Count == 0);

                functionImportHelper.TryCreateFunctionImportMappingComposableWithScalarResult(
                    functionImport,
                    cTypeTargetFunction,
                    targetFunction,
                    resultType,
                    cTypeTvfElementType,
                    LineInfo.Empty,
                    out mapping);
            }

            if (mapping == null)
            {
                throw new InvalidOperationException(errors.Count > 0 ? errors[0].Message : String.Empty);
            }

            _containerMapping        = mapping._containerMapping;
            m_commandParameters      = mapping.m_commandParameters;
            m_structuralTypeMappings = mapping.m_structuralTypeMappings;
            m_targetFunctionKeys     = mapping.m_targetFunctionKeys;
            _resultMapping           = resultMapping;
        }
Exemple #21
0
 internal InputForComputingCellGroups(EntityContainerMapping containerMapping, ConfigViewGenerator config)
 {
     ContainerMapping = containerMapping;
     Config           = config;
 }
Exemple #22
0
 internal AssociationSetMapping(AssociationSet associationSet, EntityContainerMapping containerMapping)
     : base(containerMapping)
 {
     _associationSet = associationSet;
 }
Exemple #23
0
        /// <summary>
        /// Initializes a new AssociationSetMapping instance.
        /// </summary>
        /// <param name="associationSet">The association set to be mapped.</param>
        /// <param name="storeEntitySet">The store entity set to be mapped.</param>
        /// <param name="containerMapping">The parent container mapping.</param>
        public AssociationSetMapping(AssociationSet associationSet, EntitySet storeEntitySet, EntityContainerMapping containerMapping)
            : base(containerMapping)
        {
            Check.NotNull(associationSet, "associationSet");
            Check.NotNull(storeEntitySet, "storeEntitySet");

            _associationSet         = associationSet;
            _associationTypeMapping = new AssociationTypeMapping(associationSet.ElementType, this);
            _associationTypeMapping.MappingFragment
                = new MappingFragment(storeEntitySet, _associationTypeMapping, false);
        }
        /// <summary>
        /// Initializes a new FunctionImportMappingComposable instance.
        /// </summary>
        /// <param name="functionImport">The model function import.</param>
        /// <param name="targetFunction">The store composable function.</param>
        /// <param name="resultMapping">The result mapping for the function import.</param>
        /// <param name="containerMapping">The parent container mapping.</param>
        public FunctionImportMappingComposable(
            EdmFunction functionImport,
            EdmFunction targetFunction,
            FunctionImportResultMapping resultMapping,
            EntityContainerMapping containerMapping)
            : base(
                Check.NotNull(functionImport, "functionImport"),
                Check.NotNull(targetFunction, "targetFunction"))
        {
            Check.NotNull(resultMapping, "resultMapping");
            Check.NotNull(containerMapping, "containerMapping");

            if (!functionImport.IsComposableAttribute)
            {
                throw new ArgumentException(Strings.NonComposableFunctionCannotBeMappedAsComposable("functionImport"));
            }

            if (!targetFunction.IsComposableAttribute)
            {
                throw new ArgumentException(Strings.NonComposableFunctionCannotBeMappedAsComposable("targetFunction"));
            }

            if (functionImport.EntitySet != null)
            {
                throw new NotSupportedException(Strings.ComposableFunctionImportsReturningEntitiesNotSupported);
            }

            EdmType resultType;

            if (!MetadataHelper.TryGetFunctionImportReturnType(functionImport, 0, out resultType))
            {
                throw new ArgumentException(Strings.InvalidReturnTypeForComposableFunction);
            }

            // Function mapping is allowed only for TVFs on the s-space.
            var cTypeTargetFunction = containerMapping.StorageMappingItemCollection.StoreItemCollection.ConvertToCTypeFunction(targetFunction);
            var cTypeTvfElementType = TypeHelpers.GetTvfReturnType(cTypeTargetFunction);
            var sTypeTvfElementType = TypeHelpers.GetTvfReturnType(targetFunction);

            if (cTypeTvfElementType == null)
            {
                Debug.Assert(sTypeTvfElementType == null);

                throw new ArgumentException(
                          Strings.Mapping_FunctionImport_ResultMapping_InvalidSType(functionImport.Identity),
                          "functionImport");
            }

            var errors = new List <EdmSchemaError>();
            var functionImportHelper = new FunctionImportMappingComposableHelper(
                containerMapping,
                String.Empty,
                errors);

            FunctionImportMappingComposable mapping;

            if (Helper.IsStructuralType(resultType))
            {
                functionImportHelper.TryCreateFunctionImportMappingComposableWithStructuralResult(
                    functionImport,
                    cTypeTargetFunction,
                    resultMapping.SourceList,
                    cTypeTvfElementType,
                    sTypeTvfElementType,
                    LineInfo.Empty,
                    out mapping);
            }
            else
            {
                Debug.Assert(TypeSemantics.IsScalarType(resultType));
                Debug.Assert(resultMapping.TypeMappings.Count == 0);

                functionImportHelper.TryCreateFunctionImportMappingComposableWithScalarResult(
                    functionImport,
                    cTypeTargetFunction,
                    targetFunction,
                    resultType,
                    cTypeTvfElementType,
                    LineInfo.Empty,
                    out mapping);
            }

            if (mapping == null)
            {
                throw new InvalidOperationException(errors.Count > 0 ? errors[0].Message : String.Empty);
            }

            _containerMapping        = mapping._containerMapping;
            m_commandParameters      = mapping.m_commandParameters;
            m_structuralTypeMappings = mapping.m_structuralTypeMappings;
            m_targetFunctionKeys     = mapping.m_targetFunctionKeys;
            _resultMapping           = resultMapping;
        }