public void Can_add_and_get_entity_set_mapping()
        {
            var dummy = CreateEntityType("e");
            var es1 = EntitySet.Create("es1", null, null, null, dummy, null);
            var es2 = EntitySet.Create("es2", null, null, null, dummy, null);

            var mappingContext = new SimpleMappingContext(new EdmModel(DataSpace.SSpace), true);
            mappingContext.AddMapping(es1, es2);
            Assert.Same(es2, mappingContext[es1]);

            EntitySet outEntitySet;

            Assert.True(mappingContext.TryGetValue(es1, out outEntitySet));
            Assert.Same(es2, outEntitySet);

            Assert.False(mappingContext.TryGetValue(es2, out outEntitySet));
            Assert.Null(outEntitySet);
        }
        public void Can_add_and_get_entity_set_mapping()
        {
            var dummy = CreateEntityType("e");
            var es1   = EntitySet.Create("es1", null, null, null, dummy, null);
            var es2   = EntitySet.Create("es2", null, null, null, dummy, null);

            var mappingContext = new SimpleMappingContext(new EdmModel(DataSpace.SSpace), true);

            mappingContext.AddMapping(es1, es2);
            Assert.Same(es2, mappingContext[es1]);

            EntitySet outEntitySet;

            Assert.True(mappingContext.TryGetValue(es1, out outEntitySet));
            Assert.Same(es2, outEntitySet);

            Assert.False(mappingContext.TryGetValue(es2, out outEntitySet));
            Assert.Null(outEntitySet);
        }
Exemplo n.º 3
0
        private void GenerateAssociationSet(
            SimpleMappingContext mappingContext,
            AssociationSet storeAssociationSet,
            UniqueIdentifierService uniqueEntityContainerNames,
            UniqueIdentifierService globallyUniqueTypeNames)
        {
            // We will get a value when the same association type is used for multiple association sets.
            AssociationType conceptualAssociationType;

            if (!mappingContext.TryGetValue(storeAssociationSet.ElementType, out conceptualAssociationType))
            {
                conceptualAssociationType = GenerateAssociationType(
                    mappingContext,
                    storeAssociationSet.ElementType,
                    globallyUniqueTypeNames);
            }

            Debug.Assert(storeAssociationSet.AssociationSetEnds.Count == 2);
            var storeSetEnd0 = storeAssociationSet.AssociationSetEnds[0];
            var storeSetEnd1 = storeAssociationSet.AssociationSetEnds[1];

            EntitySet conceptualEntitySet0, conceptualEntitySet1;

            mappingContext.TryGetValue(storeSetEnd0.EntitySet, out conceptualEntitySet0);
            mappingContext.TryGetValue(storeSetEnd1.EntitySet, out conceptualEntitySet1);

            var conceptualAssociationSet = AssociationSet.Create(
                CreateModelName(storeAssociationSet.Name, uniqueEntityContainerNames),
                conceptualAssociationType,
                conceptualEntitySet0,
                conceptualEntitySet1,
                null);

            Debug.Assert(conceptualAssociationSet.AssociationSetEnds.Count == 2);
            var conceptualSetEnd0 = conceptualAssociationSet.AssociationSetEnds[0];
            var conceptualSetEnd1 = conceptualAssociationSet.AssociationSetEnds[1];

            mappingContext.AddMapping(storeAssociationSet, conceptualAssociationSet);
            mappingContext.AddMapping(storeSetEnd0, conceptualSetEnd0);
            mappingContext.AddMapping(storeSetEnd1, conceptualSetEnd1);
        }
        public void Can_add_get_association_type_mapping()
        {
            var storeAssociationType =
                AssociationType.Create("storeAssociationType", "ns.Store", false, DataSpace.SSpace, null, null, null, null);
            var conceptualAssociationType =
                AssociationType.Create("conceptualAssociationType", "ns", false, DataSpace.CSpace, null, null, null, null);

            var mappingContext = new SimpleMappingContext(new EdmModel(DataSpace.SSpace), true);

            mappingContext.AddMapping(storeAssociationType, conceptualAssociationType);

            Assert.Same(conceptualAssociationType, mappingContext[storeAssociationType]);

            AssociationType outAssociationType;

            Assert.True(mappingContext.TryGetValue(storeAssociationType, out outAssociationType));
            Assert.Same(conceptualAssociationType, outAssociationType);

            Assert.False(mappingContext.TryGetValue(conceptualAssociationType, out outAssociationType));
            Assert.Null(outAssociationType);
        }
        public void Can_add_get_association_type_mapping()
        {
            var storeAssociationType =
                AssociationType.Create("storeAssociationType", "ns.Store", false, DataSpace.SSpace, null, null, null, null);
            var conceptualAssociationType =
                AssociationType.Create("conceptualAssociationType", "ns", false, DataSpace.CSpace, null, null, null, null);

            var mappingContext = new SimpleMappingContext(new EdmModel(DataSpace.SSpace), true);
            mappingContext.AddMapping(storeAssociationType, conceptualAssociationType);

            Assert.Same(conceptualAssociationType, mappingContext[storeAssociationType]);

            AssociationType outAssociationType;
            Assert.True(mappingContext.TryGetValue(storeAssociationType, out outAssociationType));
            Assert.Same(conceptualAssociationType, outAssociationType);

            Assert.False(mappingContext.TryGetValue(conceptualAssociationType, out outAssociationType));
            Assert.Null(outAssociationType);
        }
        private void GenerateAssociationSet(
            SimpleMappingContext mappingContext,
            AssociationSet storeAssociationSet,
            UniqueIdentifierService uniqueEntityContainerNames,
            UniqueIdentifierService globallyUniqueTypeNames)
        {
            // We will get a value when the same association type is used for multiple association sets.
            AssociationType conceptualAssociationType;
            if (!mappingContext.TryGetValue(storeAssociationSet.ElementType, out conceptualAssociationType))
            {
                conceptualAssociationType = GenerateAssociationType(
                    mappingContext,
                    storeAssociationSet.ElementType,
                    globallyUniqueTypeNames);
            }

            Debug.Assert(storeAssociationSet.AssociationSetEnds.Count == 2);
            var storeSetEnd0 = storeAssociationSet.AssociationSetEnds[0];
            var storeSetEnd1 = storeAssociationSet.AssociationSetEnds[1];

            EntitySet conceptualEntitySet0, conceptualEntitySet1;
            mappingContext.TryGetValue(storeSetEnd0.EntitySet, out conceptualEntitySet0);
            mappingContext.TryGetValue(storeSetEnd1.EntitySet, out conceptualEntitySet1);

            var conceptualAssociationSet = AssociationSet.Create(
                CreateModelName(storeAssociationSet.Name, uniqueEntityContainerNames),
                conceptualAssociationType,
                conceptualEntitySet0,
                conceptualEntitySet1,
                null);

            Debug.Assert(conceptualAssociationSet.AssociationSetEnds.Count == 2);
            var conceptualSetEnd0 = conceptualAssociationSet.AssociationSetEnds[0];
            var conceptualSetEnd1 = conceptualAssociationSet.AssociationSetEnds[1];

            mappingContext.AddMapping(storeAssociationSet, conceptualAssociationSet);
            mappingContext.AddMapping(storeSetEnd0, conceptualSetEnd0);
            mappingContext.AddMapping(storeSetEnd1, conceptualSetEnd1);
        }