コード例 #1
0
        private void GenerateIndependentAssociationType(
            AssociationType associationType,
            DbDatabaseMapping databaseMapping)
        {
            AssociationEndMember principalEnd;
            AssociationEndMember dependentEnd;

            if (!associationType.TryGuessPrincipalAndDependentEnds(out principalEnd, out dependentEnd))
            {
                if (!associationType.IsPrincipalConfigured())
                {
                    throw Error.UnableToDeterminePrincipal((object)EntityTypeExtensions.GetClrType(associationType.SourceEnd.GetEntityType()), (object)EntityTypeExtensions.GetClrType(associationType.TargetEnd.GetEntityType()));
                }
                principalEnd = associationType.SourceEnd;
                dependentEnd = associationType.TargetEnd;
            }
            EntityTypeMapping     mappingInHierarchy = StructuralTypeMappingGenerator.GetEntityTypeMappingInHierarchy(databaseMapping, dependentEnd.GetEntityType());
            EntityType            table = mappingInHierarchy.MappingFragments.First <MappingFragment>().Table;
            AssociationSetMapping associationSetMapping = AssociationTypeMappingGenerator.GenerateAssociationSetMapping(associationType, databaseMapping, principalEnd, dependentEnd, table);

            this.GenerateIndependentForeignKeyConstraint(databaseMapping, principalEnd.GetEntityType(), dependentEnd.GetEntityType(), table, associationSetMapping, associationSetMapping.SourceEndMapping, associationType.Name, principalEnd, false);
            foreach (EdmProperty keyProperty in dependentEnd.GetEntityType().KeyProperties())
            {
                associationSetMapping.TargetEndMapping.AddPropertyMapping(new ScalarPropertyMapping(keyProperty, mappingInHierarchy.GetPropertyMapping(keyProperty).ColumnProperty));
            }
        }
コード例 #2
0
        private void GenerateManyToManyAssociation(
            AssociationType associationType,
            DbDatabaseMapping databaseMapping)
        {
            EntityType            entityType1           = associationType.SourceEnd.GetEntityType();
            EntityType            entityType2           = associationType.TargetEnd.GetEntityType();
            EntityType            dependentTable        = databaseMapping.Database.AddTable(entityType1.Name + entityType2.Name);
            AssociationSetMapping associationSetMapping = AssociationTypeMappingGenerator.GenerateAssociationSetMapping(associationType, databaseMapping, associationType.SourceEnd, associationType.TargetEnd, dependentTable);

            this.GenerateIndependentForeignKeyConstraint(databaseMapping, entityType1, entityType2, dependentTable, associationSetMapping, associationSetMapping.SourceEndMapping, associationType.SourceEnd.Name, (AssociationEndMember)null, true);
            this.GenerateIndependentForeignKeyConstraint(databaseMapping, entityType2, entityType1, dependentTable, associationSetMapping, associationSetMapping.TargetEndMapping, associationType.TargetEnd.Name, (AssociationEndMember)null, true);
        }
コード例 #3
0
 public void Generate(AssociationType associationType, DbDatabaseMapping databaseMapping)
 {
     if (associationType.Constraint != null)
     {
         AssociationTypeMappingGenerator.GenerateForeignKeyAssociationType(associationType, databaseMapping);
     }
     else if (associationType.IsManyToMany())
     {
         this.GenerateManyToManyAssociation(associationType, databaseMapping);
     }
     else
     {
         this.GenerateIndependentAssociationType(associationType, databaseMapping);
     }
 }