Exemple #1
0
        private static EntityContainerMapping BuildEntityContainerMapping(SimpleMappingContext mappingContext)
        {
            var storeEntityContainer   = mappingContext.StoreModel.Containers.Single();
            var entityContainerMapping =
                new EntityContainerMapping(
                    mappingContext[storeEntityContainer],
                    storeEntityContainer,
                    null,
                    false,
                    false);

            foreach (var entitySetMapping in BuildEntitySetMappings(entityContainerMapping, mappingContext))
            {
                entityContainerMapping.AddSetMapping(entitySetMapping);
            }

            foreach (var associationSetMapping in BuildAssociationSetMappings(entityContainerMapping, mappingContext))
            {
                entityContainerMapping.AddSetMapping(associationSetMapping);
            }

            foreach (var mappedStoredFunction in mappingContext.MappedStoreFunctions())
            {
                entityContainerMapping.AddFunctionImportMapping(
                    BuildComposableFunctionMapping(mappedStoredFunction, mappingContext));
            }

            return(entityContainerMapping);
        }
        private static EntityContainerMapping BuildEntityContainerMapping(SimpleMappingContext mappingContext)
        {
            var storeEntityContainer = mappingContext.StoreModel.Containers.Single();
            var entityContainerMapping =
                new EntityContainerMapping(
                    mappingContext[storeEntityContainer],
                    storeEntityContainer,
                    null,
                    false,
                    false);

            foreach (var entitySetMapping in BuildEntitySetMappings(entityContainerMapping, mappingContext))
            {
                entityContainerMapping.AddSetMapping(entitySetMapping);
            }

            foreach (var associationSetMapping in BuildAssociationSetMappings(entityContainerMapping, mappingContext))
            {
                entityContainerMapping.AddSetMapping(associationSetMapping);
            }

            foreach (var mappedStoredFunction in mappingContext.MappedStoreFunctions())
            {
                entityContainerMapping.AddFunctionImportMapping(
                    BuildComposableFunctionMapping(mappedStoredFunction, mappingContext));
            }

            return entityContainerMapping;
        }
Exemple #3
0
        public void WriteFunctionImportMappingElement_writes_result_mapping_for_non_composable_functions_mapped_explicitly_to_EntityType()
        {
            var typeUsage =
                TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32));

            var entityTypeProperty1 = new EdmProperty("ETProperty1", typeUsage);
            var entityTypeProperty2 = new EdmProperty("ETProperty2", typeUsage);

            var entityType = new EntityType("ET", "Ns", DataSpace.CSpace);

            entityType.AddMember(entityTypeProperty1);
            entityType.AddMember(entityTypeProperty2);

            var functionImport =
                new EdmFunction(
                    "f_c", "Ns", DataSpace.CSpace,
                    new EdmFunctionPayload
            {
                IsComposable     = false,
                IsFunctionImport = true,
                ReturnParameters =
                    new[]
                {
                    new FunctionParameter(
                        "ReturnValue",
                        TypeUsage.CreateDefaultTypeUsage(entityType.GetCollectionType()),
                        ParameterMode.ReturnValue)
                },
            });

            typeUsage = ProviderRegistry.Sql2008_ProviderManifest.GetStoreType(typeUsage);
            var rowTypeProperty1 = new EdmProperty("RTProperty1", typeUsage);
            var rowTypeProperty2 = new EdmProperty("RTProperty2", typeUsage);
            var rowType          = new RowType(new[] { rowTypeProperty1, rowTypeProperty2 });

            var storeFunction =
                new EdmFunction(
                    "f_s", "Ns.Store", DataSpace.SSpace,
                    new EdmFunctionPayload
            {
                IsComposable     = false,
                ReturnParameters =
                    new[]
                {
                    new FunctionParameter(
                        "Return",
                        TypeUsage.CreateDefaultTypeUsage(rowType),
                        ParameterMode.ReturnValue)
                },
            });

            var functionImportResultMapping = new FunctionImportResultMapping();

            functionImportResultMapping.AddTypeMapping(
                new FunctionImportEntityTypeMapping(
                    new EntityType[0],
                    new [] { entityType },
                    new Collections.ObjectModel.Collection <FunctionImportReturnTypePropertyMapping>()
            {
                new FunctionImportReturnTypeScalarPropertyMapping("ETProperty1", "RTProperty1"),
                new FunctionImportReturnTypeScalarPropertyMapping("ETProperty2", "RTProperty2")
            },
                    new FunctionImportEntityTypeMappingCondition[]
            {
                new FunctionImportEntityTypeMappingConditionIsNull("RTProperty1", false),
                new FunctionImportEntityTypeMappingConditionValue("RTProperty2", 4),
                new FunctionImportEntityTypeMappingConditionValue("FakeCondition", true)
            }
                    ));

            var mappingItemCollection =
                new StorageMappingItemCollection(
                    new EdmItemCollection(EdmModel.CreateConceptualModel()),
                    new StoreItemCollection(
                        EdmModel.CreateStoreModel(ProviderRegistry.Sql2008_ProviderInfo, ProviderRegistry.Sql2008_ProviderManifest)),
                    new string[0]);

            var containerMapping =
                new EntityContainerMapping(
                    new EntityContainer("C", DataSpace.CSpace), new EntityContainer("S", DataSpace.SSpace), mappingItemCollection, false);

            var functionImportMapping =
                new FunctionImportMappingNonComposable(
                    functionImport,
                    storeFunction,
                    new []
            {
                functionImportResultMapping
            },
                    containerMapping);

            containerMapping.AddFunctionImportMapping(functionImportMapping);

            var fixture = new Fixture();

            fixture.Writer.WriteFunctionImportMappingElement(functionImportMapping);
            Assert.Equal(
                @"<FunctionImportMapping FunctionName=""Ns.Store.f_s"" FunctionImportName=""f_c"">
  <ResultMapping>
    <EntityTypeMapping TypeName=""Ns.ET"">
      <ScalarProperty Name=""ETProperty1"" ColumnName=""RTProperty1"" />
      <ScalarProperty Name=""ETProperty2"" ColumnName=""RTProperty2"" />
      <Condition ColumnName=""RTProperty1"" IsNull=""false"" />
      <Condition ColumnName=""RTProperty2"" Value=""4"" />
      <Condition ColumnName=""FakeCondition"" Value=""1"" />
    </EntityTypeMapping>
  </ResultMapping>
</FunctionImportMapping>",
                fixture.ToString());
        }
Exemple #4
0
        public void WriteEntityContainerMappingElement_should_write_function_import_elements_mapped_to_EntityType()
        {
            var typeUsage =
                TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32));

            var entityTypeProperty1 = new EdmProperty("ETProperty1", typeUsage);
            var entityTypeProperty2 = new EdmProperty("ETProperty2", typeUsage);

            var entityType = new EntityType("ET", "Ns", DataSpace.CSpace);

            entityType.AddMember(entityTypeProperty1);
            entityType.AddMember(entityTypeProperty2);

            var functionImport =
                new EdmFunction(
                    "f_c", "Ns", DataSpace.CSpace,
                    new EdmFunctionPayload
            {
                IsComposable     = true,
                IsFunctionImport = true,
                ReturnParameters =
                    new[]
                {
                    new FunctionParameter(
                        "ReturnValue",
                        TypeUsage.CreateDefaultTypeUsage(entityType.GetCollectionType()),
                        ParameterMode.ReturnValue)
                },
                Parameters =
                    new[]
                {
                    new FunctionParameter("param", typeUsage, ParameterMode.Out)
                }
            });

            typeUsage = ProviderRegistry.Sql2008_ProviderManifest.GetStoreType(typeUsage);
            var rowTypeProperty1 = new EdmProperty("RTProperty1", typeUsage);
            var rowTypeProperty2 = new EdmProperty("RTProperty2", typeUsage);
            var rowType          = new RowType(new[] { rowTypeProperty1, rowTypeProperty2 });

            var storeFunction =
                new EdmFunction(
                    "f_s", "Ns.Store", DataSpace.SSpace,
                    new EdmFunctionPayload
            {
                ReturnParameters =
                    new[]
                {
                    new FunctionParameter(
                        "Return",
                        TypeUsage.CreateDefaultTypeUsage(rowType),
                        ParameterMode.ReturnValue)
                },
                Parameters =
                    new[]
                {
                    new FunctionParameter("param", typeUsage, ParameterMode.Out)
                }
            });

            var structuralTypeMapping =
                new Tuple <StructuralType, List <ConditionPropertyMapping>, List <PropertyMapping> >(
                    entityType, new List <ConditionPropertyMapping>(), new List <PropertyMapping>());

            structuralTypeMapping.Item2.Add(new ConditionPropertyMapping(rowTypeProperty1, null, false));

            structuralTypeMapping.Item3.Add(new ScalarPropertyMapping(entityTypeProperty1, rowTypeProperty1));
            structuralTypeMapping.Item3.Add(new ScalarPropertyMapping(entityTypeProperty2, rowTypeProperty2));

            var functionImportMapping = new FunctionImportMappingComposable(
                functionImport,
                storeFunction,
                new List <Tuple <StructuralType, List <ConditionPropertyMapping>, List <PropertyMapping> > >
            {
                structuralTypeMapping
            });

            var containerMapping = new EntityContainerMapping(new EntityContainer("C", DataSpace.SSpace));

            containerMapping.AddFunctionImportMapping(functionImportMapping);

            var fixture = new Fixture();

            fixture.Writer.WriteEntityContainerMappingElement(containerMapping);

            Assert.Equal(
                @"<EntityContainerMapping StorageEntityContainer="""" CdmEntityContainer=""C"">
  <FunctionImportMapping FunctionName=""Ns.Store.f_s"" FunctionImportName=""f_c"">
    <ResultMapping>
      <EntityTypeMapping TypeName=""Ns.ET"">
        <Condition IsNull=""false"" ColumnName=""RTProperty1"" />
        <ScalarProperty Name=""ETProperty1"" ColumnName=""RTProperty1"" />
        <ScalarProperty Name=""ETProperty2"" ColumnName=""RTProperty2"" />
      </EntityTypeMapping>
    </ResultMapping>
  </FunctionImportMapping>
</EntityContainerMapping>",
                fixture.ToString());
        }
        public void WriteFunctionImportMappingElement_writes_result_mapping_for_non_composable_functions_mapped_explicitly_to_EntityType()
        {
            var typeUsage =
                TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32));

            var entityTypeProperty1 = new EdmProperty("ETProperty1", typeUsage);
            var entityTypeProperty2 = new EdmProperty("ETProperty2", typeUsage);

            var entityType = new EntityType("ET", "Ns", DataSpace.CSpace);
            entityType.AddMember(entityTypeProperty1);
            entityType.AddMember(entityTypeProperty2);

            var functionImport =
                new EdmFunction(
                    "f_c", "Ns", DataSpace.CSpace,
                    new EdmFunctionPayload
                    {
                        IsComposable = false,
                        IsFunctionImport = true,
                        ReturnParameters =
                            new[]
                                    {
                                        new FunctionParameter(
                                            "ReturnValue",
                                            TypeUsage.CreateDefaultTypeUsage(entityType.GetCollectionType()),
                                            ParameterMode.ReturnValue)
                                    },
                    });

            typeUsage = ProviderRegistry.Sql2008_ProviderManifest.GetStoreType(typeUsage);
            var rowTypeProperty1 = new EdmProperty("RTProperty1", typeUsage);
            var rowTypeProperty2 = new EdmProperty("RTProperty2", typeUsage);
            var rowType = new RowType(new[] { rowTypeProperty1, rowTypeProperty2 });

            var storeFunction =
                new EdmFunction(
                    "f_s", "Ns.Store", DataSpace.SSpace,
                    new EdmFunctionPayload
                    {
                        IsComposable = false,
                        ReturnParameters =
                            new[]
                                    {
                                        new FunctionParameter(
                                            "Return",
                                            TypeUsage.CreateDefaultTypeUsage(rowType),
                                            ParameterMode.ReturnValue)
                                    },
                    });

            var functionImportResultMapping = new FunctionImportResultMapping();
            functionImportResultMapping.AddTypeMapping(
                new FunctionImportEntityTypeMapping(
                    new EntityType[0],
                    new [] { entityType },
                    new Collections.ObjectModel.Collection<FunctionImportReturnTypePropertyMapping>()
                    {
                        new FunctionImportReturnTypeScalarPropertyMapping("ETProperty1", "RTProperty1"),
                        new FunctionImportReturnTypeScalarPropertyMapping("ETProperty2", "RTProperty2")
                    },
                    new FunctionImportEntityTypeMappingCondition[]
                    {
                        new FunctionImportEntityTypeMappingConditionIsNull("RTProperty1", false),
                        new FunctionImportEntityTypeMappingConditionValue("RTProperty2", 4),
                        new FunctionImportEntityTypeMappingConditionValue("FakeCondition", true)
                    }
                ));

            var mappingItemCollection = 
                new StorageMappingItemCollection(
                    new EdmItemCollection(EdmModel.CreateConceptualModel()), 
                    new StoreItemCollection(
                        EdmModel.CreateStoreModel(ProviderRegistry.Sql2008_ProviderInfo, ProviderRegistry.Sql2008_ProviderManifest)), 
                        new string[0]);

            var containerMapping = 
                new EntityContainerMapping(
                    new EntityContainer("C", DataSpace.CSpace), new EntityContainer("S", DataSpace.SSpace), mappingItemCollection, false);

            var functionImportMapping =
                new FunctionImportMappingNonComposable(
                   functionImport,
                   storeFunction,
                   new []
                   {
                       functionImportResultMapping
                   },
                   containerMapping);

            containerMapping.AddFunctionImportMapping(functionImportMapping);

            var fixture = new Fixture();
            fixture.Writer.WriteFunctionImportMappingElement(functionImportMapping);
            Assert.Equal(
                @"<FunctionImportMapping FunctionName=""Ns.Store.f_s"" FunctionImportName=""f_c"">
  <ResultMapping>
    <EntityTypeMapping TypeName=""Ns.ET"">
      <ScalarProperty Name=""ETProperty1"" ColumnName=""RTProperty1"" />
      <ScalarProperty Name=""ETProperty2"" ColumnName=""RTProperty2"" />
      <Condition ColumnName=""RTProperty1"" IsNull=""false"" />
      <Condition ColumnName=""RTProperty2"" Value=""4"" />
      <Condition ColumnName=""FakeCondition"" Value=""1"" />
    </EntityTypeMapping>
  </ResultMapping>
</FunctionImportMapping>",
                fixture.ToString());
        }
        public void WriteEntityContainerMappingElement_should_write_function_import_elements_mapped_to_EntityType()
        {
            var typeUsage =
                TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32));

            var entityTypeProperty1 = new EdmProperty("ETProperty1", typeUsage);
            var entityTypeProperty2 = new EdmProperty("ETProperty2", typeUsage);

            var entityType = new EntityType("ET", "Ns", DataSpace.CSpace);
            entityType.AddMember(entityTypeProperty1);
            entityType.AddMember(entityTypeProperty2);

            var functionImport =
                new EdmFunction(
                    "f_c", "Ns", DataSpace.CSpace,
                    new EdmFunctionPayload
                    {
                        IsComposable = true,
                        IsFunctionImport = true,
                        ReturnParameters =
                            new[]
                                    {
                                        new FunctionParameter(
                                            "ReturnValue",
                                            TypeUsage.CreateDefaultTypeUsage(entityType.GetCollectionType()),
                                            ParameterMode.ReturnValue)
                                    },
                        Parameters =
                            new[]
                                    {
                                        new FunctionParameter("param", typeUsage, ParameterMode.Out)
                                    }
                    });

            typeUsage = ProviderRegistry.Sql2008_ProviderManifest.GetStoreType(typeUsage);
            var rowTypeProperty1 = new EdmProperty("RTProperty1", typeUsage);
            var rowTypeProperty2 = new EdmProperty("RTProperty2", typeUsage);
            var rowType = new RowType(new[] { rowTypeProperty1, rowTypeProperty2 });

            var storeFunction =
                new EdmFunction(
                    "f_s", "Ns.Store", DataSpace.SSpace,
                    new EdmFunctionPayload
                    {
                        ReturnParameters =
                            new[]
                                    {
                                        new FunctionParameter(
                                            "Return",
                                            TypeUsage.CreateDefaultTypeUsage(rowType),
                                            ParameterMode.ReturnValue)
                                    },
                        Parameters =
                            new[]
                                    {
                                        new FunctionParameter("param", typeUsage, ParameterMode.Out)
                                    }
                    });

            var structuralTypeMapping =
                new Tuple<StructuralType, List<ConditionPropertyMapping>, List<PropertyMapping>>(
                    entityType, new List<ConditionPropertyMapping>(), new List<PropertyMapping>());
            structuralTypeMapping.Item2.Add(new ConditionPropertyMapping(rowTypeProperty1, null, false));

            structuralTypeMapping.Item3.Add(new ScalarPropertyMapping(entityTypeProperty1, rowTypeProperty1));
            structuralTypeMapping.Item3.Add(new ScalarPropertyMapping(entityTypeProperty2, rowTypeProperty2));

            var functionImportMapping = new FunctionImportMappingComposable(
                functionImport,
                storeFunction,
                new List<Tuple<StructuralType, List<ConditionPropertyMapping>, List<PropertyMapping>>>
                    {
                        structuralTypeMapping
                    });

            var containerMapping = new EntityContainerMapping(new EntityContainer("C", DataSpace.SSpace));
            containerMapping.AddFunctionImportMapping(functionImportMapping);

            var fixture = new Fixture();
            fixture.Writer.WriteEntityContainerMappingElement(containerMapping);

            Assert.Equal(
                @"<EntityContainerMapping StorageEntityContainer="""" CdmEntityContainer=""C"">
  <FunctionImportMapping FunctionName=""Ns.Store.f_s"" FunctionImportName=""f_c"">
    <ResultMapping>
      <EntityTypeMapping TypeName=""Ns.ET"">
        <Condition IsNull=""false"" ColumnName=""RTProperty1"" />
        <ScalarProperty Name=""ETProperty1"" ColumnName=""RTProperty1"" />
        <ScalarProperty Name=""ETProperty2"" ColumnName=""RTProperty2"" />
      </EntityTypeMapping>
    </ResultMapping>
  </FunctionImportMapping>
</EntityContainerMapping>",
                fixture.ToString());
        }
        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 composableFuntionMapping =
                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(composableFuntionMapping);
            Assert.Same(composableFuntionMapping, entityContainerMapping.FunctionImportMappings.Single());
        }
        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 functionImporMapping 
                = new FunctionImportMappingFake(
                    new EdmFunction("FI", "N", DataSpace.CSpace),
                    new EdmFunction("TF", "N", DataSpace.SSpace));

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

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

            containerMapping.SetReadOnly();

            Assert.True(containerMapping.IsReadOnly);
            Assert.True(entitySetMapping.IsReadOnly);
            Assert.True(associationSetMapping.IsReadOnly);
            Assert.True(functionImporMapping.IsReadOnly);
        }