public void Can_retrieve_properties()
        {
            var source    = new EntityType("Source", "N", DataSpace.CSpace);
            var target    = new EntityType("Target", "N", DataSpace.CSpace);
            var sourceEnd = new AssociationEndMember("SourceEnd", source);
            var targetEnd = new AssociationEndMember("TargetEnd", target);
            var associationType
                = AssociationType.Create(
                      "AT",
                      "N",
                      true,
                      DataSpace.CSpace,
                      sourceEnd,
                      targetEnd,
                      null,
                      null);
            var sourceSet = new EntitySet("SourceSet", "S", "T", "Q", source);
            var targetSet = new EntitySet("TargetSet", "S", "T", "Q", target);
            var associationSet
                = AssociationSet.Create(
                      "AS",
                      associationType,
                      sourceSet,
                      targetSet,
                      null);

            var members = new List <EdmMember> {
                null, targetEnd
            };
            var memberPath = new ModificationFunctionMemberPath(members, associationSet);

            Assert.Equal(members, memberPath.Members);
            Assert.Equal(targetEnd.Name, memberPath.AssociationSetEnd.Name);
        }
        public void Can_add_and_get_association_type_mapping()
        {
            var at1 = AssociationType.Create("at1", "ns", false, DataSpace.CSpace, null, null, null, null);
            var at2 = AssociationType.Create("at2", "ns", false, DataSpace.CSpace, null, null, null, null);

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

            mappingContext.AddMapping(at1, at2);

            Assert.Same(at2, mappingContext[at1]);
        }
        private static SimpleMappingContext CreateSimpleMappingContext(bool isForeignKey)
        {
            var int32TypeUsage = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32));
            var storeP1        = new[] { CreateStoreProperty("storeSourceId", "int") };
            var storeP2        = new[] { CreateStoreProperty("storeTargetId", "int") };
            var modelP1        = new[] { EdmProperty.Create("modelSourceId", int32TypeUsage) };
            var modelP2        = new[] { EdmProperty.Create("modelTargetId", int32TypeUsage) };
            var storeET1       = EntityType.Create("storeET1", "N", DataSpace.SSpace, new[] { "storeSourceId" }, storeP1, null);
            var storeET2       = EntityType.Create("storeET2", "N", DataSpace.SSpace, new[] { "storeTargetId" }, storeP2, null);
            var modelET1       = EntityType.Create("modelET1", "N", DataSpace.CSpace, new[] { "modelSourceId" }, modelP1, null);
            var modelET2       = EntityType.Create("modelET2", "N", DataSpace.CSpace, new[] { "modelTargetId" }, modelP2, null);
            var storeES1       = EntitySet.Create("storeES1", null, null, null, storeET1, null);
            var storeES2       = EntitySet.Create("storeES2", null, null, null, storeET2, null);
            var modelES1       = EntitySet.Create("modelES1", null, null, null, modelET1, null);
            var modelES2       = EntitySet.Create("modelES2", null, null, null, modelET2, null);
            var storeEM1       = AssociationEndMember.Create(
                "storeEM1", storeET1.GetReferenceType(), RelationshipMultiplicity.One, OperationAction.None, null);
            var storeEM2 = AssociationEndMember.Create(
                "storeEM2", storeET2.GetReferenceType(), RelationshipMultiplicity.One, OperationAction.None, null);
            var modelEM1 = AssociationEndMember.Create(
                "modelEM1", modelET1.GetReferenceType(), RelationshipMultiplicity.Many, OperationAction.None, null);
            var modelEM2 = AssociationEndMember.Create(
                "modelEM2", modelET2.GetReferenceType(), RelationshipMultiplicity.Many, OperationAction.None, null);
            var storeRC        = new ReferentialConstraint(storeEM1, storeEM2, storeP1, storeP2);
            var modelRC        = new ReferentialConstraint(modelEM1, modelEM2, modelP1, modelP2);
            var storeAT        = AssociationType.Create("storeAT", "N", isForeignKey, DataSpace.SSpace, storeEM1, storeEM2, storeRC, null);
            var modelAT        = AssociationType.Create("modelAT", "N", isForeignKey, DataSpace.CSpace, modelEM1, modelEM2, modelRC, null);
            var storeAS        = AssociationSet.Create("storeAS", storeAT, storeES1, storeES2, null);
            var modelAS        = AssociationSet.Create("modelAS", modelAT, modelES1, modelES2, null);
            var storeContainer = EntityContainer.Create(
                "storeContainer", DataSpace.SSpace, new EntitySetBase[] { storeES1, storeES2, storeAS }, null, null);
            var modelContainer = EntityContainer.Create(
                "modelContainer", DataSpace.CSpace, new EntitySetBase[] { modelES1, modelES2, modelAS }, null, null);

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

            mappingContext.AddMapping(storeP1[0], modelP1[0]);
            mappingContext.AddMapping(storeP2[0], modelP2[0]);
            mappingContext.AddMapping(storeET1, modelET1);
            mappingContext.AddMapping(storeET2, modelET2);
            mappingContext.AddMapping(storeES1, modelES1);
            mappingContext.AddMapping(storeES2, modelES2);
            mappingContext.AddMapping(storeEM1, modelEM1);
            mappingContext.AddMapping(storeEM2, modelEM2);
            mappingContext.AddMapping(storeAT, modelAT);
            mappingContext.AddMapping(storeAS, modelAS);
            mappingContext.AddMapping(storeAS.AssociationSetEnds[0], modelAS.AssociationSetEnds[0]);
            mappingContext.AddMapping(storeAS.AssociationSetEnds[1], modelAS.AssociationSetEnds[1]);
            mappingContext.AddMapping(storeContainer, modelContainer);

            return(mappingContext);
        }
        public void Can_add_and_get_mapping_for_collapsed_entity_sets()
        {
            var storeEntity               = CreateEntityType("storeEntity");
            var storeEntitySet            = EntitySet.Create("storeEntitySet", null, null, null, storeEntity, null);
            var collapsibleAssociationSet = new CollapsibleEntityAssociationSets(storeEntitySet);

            var associationType = AssociationType.Create("modelAssociationType", "ns", false, DataSpace.CSpace, null, null, null, null);
            var associationSet  = AssociationSet.Create("modelAssociationType", associationType, null, null, null);

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

            mappingContext.AddMapping(collapsibleAssociationSet, associationSet);

            Assert.Same(associationSet, mappingContext[collapsibleAssociationSet]);
        }
        public void ConceptualAssociationSets_returns_associationsets_for_collapsed_entity_sets()
        {
            var storeEntity               = CreateEntityType("storeEntity");
            var storeEntitySet            = EntitySet.Create("storeEntitySet", null, null, null, storeEntity, null);
            var collapsibleAssociationSet = new CollapsibleEntityAssociationSets(storeEntitySet);

            var associationType = AssociationType.Create("modelAssociationType", "ns", false, DataSpace.CSpace, null, null, null, null);
            var associationSet  = AssociationSet.Create("modelAssociationType", associationType, null, null, null);

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

            Assert.Empty(mappingContext.ConceptualAssociationSets());

            mappingContext.AddMapping(collapsibleAssociationSet, associationSet);
            Assert.Equal(1, mappingContext.ConceptualAssociationSets().Count());
            Assert.Same(associationSet, mappingContext.ConceptualAssociationSets().Single());
        }
Exemple #6
0
        private AssociationType GenerateAssociationType(
            SimpleMappingContext mappingContext,
            AssociationType storeAssociationType,
            UniqueIdentifierService globallyUniqueTypeNames)
        {
            Debug.Assert(storeAssociationType.RelationshipEndMembers.Count == 2);

            var storeEndMember0 = (AssociationEndMember)storeAssociationType.RelationshipEndMembers[0];
            var storeEndMember1 = (AssociationEndMember)storeAssociationType.RelationshipEndMembers[1];

            var storeSchemaVersion = EntityFrameworkVersion.DoubleToVersion(mappingContext.StoreModel.SchemaVersion);
            var isFkAssociation    = storeSchemaVersion > EntityFrameworkVersion.Version1 &&
                                     (_generateForeignKeyProperties || RequiresReferentialConstraint(storeAssociationType));

            var uniqueEndMemberNames = new UniqueIdentifierService(StringComparer.OrdinalIgnoreCase);
            var multiplicityOverride = GetMultiplicityOverride(storeAssociationType);

            var conceptualEndMember0 = GenerateAssociationEndMember(
                mappingContext,
                storeEndMember0,
                uniqueEndMemberNames,
                multiplicityOverride);

            var conceptualEndMember1 = GenerateAssociationEndMember(
                mappingContext,
                storeEndMember1,
                uniqueEndMemberNames,
                multiplicityOverride);

            var conceptualAssociationType = AssociationType.Create(
                CreateModelName(storeAssociationType.Name, globallyUniqueTypeNames),
                _namespaceName,
                isFkAssociation,
                DataSpace.CSpace,
                conceptualEndMember0,
                conceptualEndMember1,
                CreateReferentialConstraint(mappingContext, storeAssociationType),
                null);

            CreateModelNavigationProperties(conceptualAssociationType);

            mappingContext.AddMapping(storeAssociationType, conceptualAssociationType);

            return(conceptualAssociationType);
        }
        private AssociationType CreateAssociationType(ReferentialConstraint referentialConstraint)
        {
            var relationshipName = $"{this.fromEntityType.Name}_{this.toEntityType.Name}";

            var relationshipType = AssociationType.Create(
                relationshipName,
                this.fromEntityType.NamespaceName,
                // NOTE: I am blindly assuming this is true.  I think this is a
                // safe bet for my tests.
                true /*foreignKey*/,
                DataSpace.CSpace,
                this.fromAssociationEndMember,
                this.toAssociationEndMember,
                referentialConstraint,
                Enumerable.Empty <MetadataProperty>());

            return(relationshipType);
        }
        public void Can_add_get_association_set_mapping()
        {
            var storeAssociationSet =
                AssociationSet.Create(
                    "storeAssociationSet",
                    AssociationType.Create("storeAssociationType", "ns.Store", false, DataSpace.SSpace, null, null, null, null),
                    null, null, null);

            var conceptualAssociationSet =
                AssociationSet.Create(
                    "conceptualAssociationSet",
                    AssociationType.Create("conceptualAssociationType", "ns", false, DataSpace.CSpace, null, null, null, null),
                    null, null, null);

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

            mappingContext.AddMapping(storeAssociationSet, conceptualAssociationSet);

            Assert.Same(conceptualAssociationSet, mappingContext[storeAssociationSet]);
        }
        public void Can_set_get_association_set_end_details()
        {
            var entity    = EntityType.Create("E", "ns", DataSpace.CSpace, new string[0], new EdmMember[0], null);
            var entitySet = EntitySet.Create("es1", null, null, null, entity, null);
            var endMember = AssociationEndMember.Create(
                "aem1", entity.GetReferenceType(), RelationshipMultiplicity.One, OperationAction.None, null);
            var associationType = AssociationType.Create("at1", "ns", false, DataSpace.CSpace, endMember, null, null, null);
            var assocationSet   = AssociationSet.Create("as1", associationType, entitySet, null, null);

            var associationSetEnd = assocationSet.AssociationSetEnds[0];

            var associationSetEndDetails =
                new AssociationSetEndDetails(
                    associationSetEnd,
                    (RelationshipMultiplicity)(-42),
                    (OperationAction)(-100));

            Assert.Same(associationSetEnd, associationSetEndDetails.AssociationSetEnd);
            Assert.Equal(-42, (int)associationSetEndDetails.Multiplicity);
            Assert.Equal(-100, (int)associationSetEndDetails.DeleteBehavior);
        }
        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_and_get_association_set_end_mapping()
        {
            var et1  = CreateEntityType("et1");
            var et2  = CreateEntityType("et2");
            var es1  = EntitySet.Create("es1", null, null, null, et1, null);
            var es2  = EntitySet.Create("es2", null, null, null, et2, null);
            var aem1 = AssociationEndMember.Create("aem1", et1.GetReferenceType(), RelationshipMultiplicity.One, OperationAction.None, null);
            var aem2 = AssociationEndMember.Create("aem2", et2.GetReferenceType(), RelationshipMultiplicity.One, OperationAction.None, null);
            var at1  = AssociationType.Create("at1", "ns", false, DataSpace.CSpace, aem1, aem2, null, null);
            var as1  = AssociationSet.Create("as1", at1, es1, es2, null);

            Assert.Equal(2, as1.AssociationSetEnds.Count);
            var ase1 = as1.AssociationSetEnds[0];
            var ase2 = as1.AssociationSetEnds[1];

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

            mappingContext.AddMapping(ase1, ase2);

            Assert.Same(ase2, mappingContext[ase1]);
        }
        public void Build_adds_association_types_to_model()
        {
            var storeEntityType =
                EntityType.Create("foo_S", "bar_S", DataSpace.SSpace, null, null, null);
            var storeEntitySet = EntitySet.Create("ES_S", "Ns_S", null, null, storeEntityType, null);
            var storeContainer = EntityContainer.Create("C_S", DataSpace.SSpace, new[] { storeEntitySet }, null, null);
            var storeModel     = EdmModel.CreateStoreModel(storeContainer, null, null);

            var conceptualAssociationType =
                AssociationType.Create("AT_C", "ns", false, DataSpace.CSpace, null, null, null, null);
            var associationSet = AssociationSet.Create("AS_C", conceptualAssociationType, null, null, null);
            var modelContainer = EntityContainer.Create("C_C", DataSpace.CSpace, new[] { associationSet }, null, null);

            var mappingContext = new SimpleMappingContext(storeModel, true);

            mappingContext.AddMapping(storeContainer, modelContainer);
            mappingContext.AddMapping(new CollapsibleEntityAssociationSets(storeEntitySet), associationSet);

            var model = DbDatabaseMappingBuilder.Build(mappingContext);

            Assert.Same(conceptualAssociationType, model.ConceptualModel.AssociationTypes.SingleOrDefault());
        }
        public void BuildAssociationSetMappings_builds_conceptual_association_set_mapping_for_collapsed_store_entity_sets()
        {
            #region Setting up many to many relationship in the SSpace Teacher * -- 1 TeacherStudents 1 -- * Teachers

            var joinStoreEntityType =
                EntityType.Create(
                    "TeacherStudents", "ns.Store", DataSpace.SSpace,
                    new[] { "JoinTeacherId", "JoinStudentId" },
                    new[]
            {
                CreateStoreProperty("JoinTeacherId", "int"),
                CreateStoreProperty("JoinStudentId", "int")
            }, null);

            var joinStoreEntitySet =
                EntitySet.Create("TeacherStudentsSet", "dbo", "TeacherStudentTable", null, joinStoreEntityType, null);

            var storeTeacherEntityType =
                EntityType.Create(
                    "Teacher", "ns.Store", DataSpace.SSpace, new[] { "TeacherId" },
                    new[] { CreateStoreProperty("TeacherId", "int") }, null);
            var storeTeacherEntitySet =
                EntitySet.Create("TeachersSet", "dbo", "Teachers", null, storeTeacherEntityType, null);

            var storeStudentEntityType =
                EntityType.Create(
                    "Student", "ns.Store", DataSpace.SSpace, new[] { "StudentId" },
                    new[] { CreateStoreProperty("StudentId", "int") }, null);
            var storeStudentEntitySet =
                EntitySet.Create("StudentSet", "dbo", "Students", null, storeStudentEntityType, null);

            var storeTeachersEndMember =
                AssociationEndMember.Create(
                    "Teachers", storeTeacherEntityType.GetReferenceType(), RelationshipMultiplicity.Many,
                    OperationAction.None, null);

            var storeTeacherStudentsfromTeachersEndMember =
                AssociationEndMember.Create(
                    "TeacherStudents_fromTeachers", joinStoreEntityType.GetReferenceType(), RelationshipMultiplicity.One,
                    OperationAction.None, null);

            var storeTeacherAssociationType =
                AssociationType.Create(
                    "Teacher_TeacherStudentsAssociationType", "ns.Store", false, DataSpace.SSpace,
                    storeTeachersEndMember, storeTeacherStudentsfromTeachersEndMember,
                    new ReferentialConstraint(
                        storeTeachersEndMember, storeTeacherStudentsfromTeachersEndMember, storeTeacherEntityType.KeyProperties,
                        joinStoreEntityType.KeyProperties.Where(p => p.Name == "JoinTeacherId")),
                    null);

            var storeTeacherAssociationSet =
                AssociationSet.Create(
                    "Teacher_TeacherStudents", storeTeacherAssociationType, storeTeacherEntitySet, joinStoreEntitySet, null);

            var storeStudentsEndMember =
                AssociationEndMember.Create(
                    "Students", storeStudentEntityType.GetReferenceType(), RelationshipMultiplicity.Many,
                    OperationAction.None, null);

            var storeTeacherStudentsfromStudentsEndMember =
                AssociationEndMember.Create(
                    "TeacherStudents_fromStudents", joinStoreEntityType.GetReferenceType(), RelationshipMultiplicity.One,
                    OperationAction.None, null);

            var storeStudentAssociationType =
                AssociationType.Create(
                    "Student_TeacherStudentsAssociationType", "ns.Store", false, DataSpace.SSpace,
                    storeStudentsEndMember,
                    storeTeacherStudentsfromStudentsEndMember,
                    new ReferentialConstraint(
                        storeStudentsEndMember, storeTeacherStudentsfromStudentsEndMember, storeStudentEntityType.KeyProperties,
                        joinStoreEntityType.KeyProperties.Where(p => p.Name == "JoinStudentId")),
                    null);

            var storeStudentAssociationSet =
                AssociationSet.Create(
                    "Student_TeacherStudents", storeStudentAssociationType, storeStudentEntitySet, joinStoreEntitySet, null);

            var collapsedAssociationSet = new CollapsibleEntityAssociationSets(joinStoreEntitySet);
            collapsedAssociationSet.AssociationSets.Add(storeTeacherAssociationSet);
            collapsedAssociationSet.AssociationSets.Add(storeStudentAssociationSet);

            #endregion

            #region Setting up many to many relationship in the CSpace Teacher * -- * Teachers

            var conceptualContainer = EntityContainer.Create("ConceptualContainer", DataSpace.CSpace, null, null, null);

            var edmIntTypeUsage =
                TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32));

            var conceptualTeacherEntityType =
                EntityType.Create(
                    "Teacher", "ns", DataSpace.CSpace, new[] { "TeacherId" },
                    new[] { EdmProperty.Create("TeacherId", edmIntTypeUsage) }, null);

            var conceptualTeacherEntitySet =
                EntitySet.Create("TeachersSet", null, null, null, conceptualTeacherEntityType, null);

            var conceptualStudentEntityType =
                EntityType.Create(
                    "Student", "ns", DataSpace.CSpace, new[] { "StudentId" },
                    new[] { EdmProperty.Create("StudentId", edmIntTypeUsage) }, null);

            var conceptualStudentEntitySet =
                EntitySet.Create("StudentSet", "dbo", "Students", null, conceptualStudentEntityType, null);

            var conceptualTeachersEndMember =
                AssociationEndMember.Create(
                    "TeachersEnd", conceptualTeacherEntityType.GetReferenceType(), RelationshipMultiplicity.Many,
                    OperationAction.None, null);

            var conceptualStudentsEndMember =
                AssociationEndMember.Create(
                    "StudentsEnd", conceptualStudentEntityType.GetReferenceType(), RelationshipMultiplicity.Many,
                    OperationAction.None, null);

            var conceptualAssociationType =
                AssociationType.Create(
                    "TeacherStudentAssociation",
                    "ns.Model",
                    false,
                    DataSpace.CSpace,
                    conceptualTeachersEndMember,
                    conceptualStudentsEndMember,
                    new ReferentialConstraint(
                        conceptualTeachersEndMember, conceptualStudentsEndMember,
                        conceptualTeacherEntityType.KeyProperties, conceptualStudentEntityType.KeyProperties),
                    null);

            var conceptualAssociationSet =
                AssociationSet.Create(
                    "TeacherStudentSet", conceptualAssociationType, conceptualTeacherEntitySet,
                    conceptualStudentEntitySet, null);

            #endregion

            var mappingContext = new SimpleMappingContext(new EdmModel(DataSpace.SSpace), true);
            mappingContext.AddMapping(collapsedAssociationSet, conceptualAssociationSet);
            mappingContext.AddMapping(storeTeachersEndMember, conceptualTeachersEndMember);
            mappingContext.AddMapping(storeStudentsEndMember, conceptualStudentsEndMember);
            mappingContext.AddMapping(
                storeTeacherAssociationSet.AssociationSetEnds.ElementAt(0),
                conceptualAssociationSet.AssociationSetEnds.ElementAt(0));
            mappingContext.AddMapping(
                storeStudentAssociationSet.AssociationSetEnds.ElementAt(0),
                conceptualAssociationSet.AssociationSetEnds.ElementAt(1));
            mappingContext.AddMapping(
                storeStudentEntityType.KeyProperties.Single(), conceptualStudentEntityType.KeyProperties.Single());
            mappingContext.AddMapping(
                storeTeacherEntityType.KeyProperties.Single(), conceptualTeacherEntityType.KeyProperties.Single());

            var storageEntitySetMapping =
                new EntityContainerMapping(conceptualContainer, null, null, false, false);

            var associationSetMapping =
                DbDatabaseMappingBuilder.BuildAssociationSetMappings(storageEntitySetMapping, mappingContext)
                .SingleOrDefault();
            Assert.NotNull(associationSetMapping);

            var mappingFragment = associationSetMapping.TypeMappings.SingleOrDefault();
            Assert.NotNull(mappingFragment);

            var propertyMappings = mappingFragment.MappingFragments.Single().PropertyMappings;
            Assert.Equal(2, propertyMappings.Count);
            Assert.Same(conceptualTeachersEndMember, ((EndPropertyMapping)propertyMappings[0]).AssociationEnd);
            Assert.Same(conceptualStudentsEndMember, ((EndPropertyMapping)propertyMappings[1]).AssociationEnd);

            var scalarPropertyMapping = ((EndPropertyMapping)propertyMappings[0]).PropertyMappings.Single();
            Assert.Same(conceptualTeacherEntityType.KeyMembers.Single(), scalarPropertyMapping.Property);
            Assert.Same(
                joinStoreEntityType.KeyMembers.Single(m => m.Name == "JoinTeacherId"),
                scalarPropertyMapping.Column);

            scalarPropertyMapping = ((EndPropertyMapping)propertyMappings[1]).PropertyMappings.Single();
            Assert.Same(conceptualStudentEntityType.KeyMembers.Single(), scalarPropertyMapping.Property);
            Assert.Same(
                joinStoreEntityType.KeyMembers.Single(m => m.Name == "JoinStudentId"),
                scalarPropertyMapping.Column);
        }
Exemple #14
0
        private void GenerateAssociationSet(
            SimpleMappingContext mappingContext,
            CollapsibleEntityAssociationSets collapsibleItem,
            UniqueIdentifierService uniqueEntityContainerNames,
            UniqueIdentifierService globallyUniqueTypeNames)
        {
            var uniqueEndMemberNames = new UniqueIdentifierService(StringComparer.OrdinalIgnoreCase);

            var associationSetEndDetails0 = collapsibleItem.GetStoreAssociationSetEnd(0);

            var associationEndMember0 = GenerateAssociationEndMember(
                mappingContext,
                associationSetEndDetails0.AssociationSetEnd.CorrespondingAssociationEndMember,
                uniqueEndMemberNames,
                associationSetEndDetails0.Multiplicity,
                associationSetEndDetails0.DeleteBehavior);
            var conceptualEntitySet0 = mappingContext[associationSetEndDetails0.AssociationSetEnd.EntitySet];

            var associationSetEndDetails1 =
                collapsibleItem.GetStoreAssociationSetEnd(1);

            var associationEndMember1 = GenerateAssociationEndMember(
                mappingContext,
                associationSetEndDetails1.AssociationSetEnd.CorrespondingAssociationEndMember,
                uniqueEndMemberNames,
                associationSetEndDetails1.Multiplicity,
                associationSetEndDetails1.DeleteBehavior);
            var conceptualEntitySet1 = mappingContext[associationSetEndDetails1.AssociationSetEnd.EntitySet];

            globallyUniqueTypeNames.UnregisterIdentifier(mappingContext[collapsibleItem.EntitySet.ElementType].Name);
            uniqueEntityContainerNames.UnregisterIdentifier(mappingContext[collapsibleItem.EntitySet].Name);

            var associationTypeName = CreateModelName(collapsibleItem.EntitySet.Name, globallyUniqueTypeNames);
            var associationSetName  = CreateModelName(collapsibleItem.EntitySet.Name, uniqueEntityContainerNames);

            var conceptualAssociationType = AssociationType.Create(
                associationTypeName,
                _namespaceName,
                false,
                DataSpace.CSpace,
                associationEndMember0,
                associationEndMember1,
                null, // Don't need a referential constraint.
                null);

            CreateModelNavigationProperties(conceptualAssociationType);

            var conceptualAssociationSet = AssociationSet.Create(
                associationSetName,
                conceptualAssociationType,
                conceptualEntitySet0,
                conceptualEntitySet1,
                null);

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

            mappingContext.AddMapping(associationSetEndDetails0.AssociationSetEnd, conceptualSetEnd0);
            mappingContext.AddMapping(associationSetEndDetails1.AssociationSetEnd, conceptualSetEnd1);
            mappingContext.AddMapping(collapsibleItem, conceptualAssociationSet);
            mappingContext.RemoveMapping(collapsibleItem.EntitySet);
        }