public void Configure(AssociationInfo associationInfo, DbSchemaBuilder builder)
 {
     foreach (IRelationConfiguration configuration in this.members)
     {
         configuration.Configure(associationInfo, builder);
     }
 }
Example #2
0
        public void Configure(AssociationInfo associationInfo, DbSchemaBuilder builder)
        {
            var primary = associationInfo.PrimaryTable;
            var foreign = associationInfo.ForeignTable;

            DbTableInfoBuilder primaryTable = builder.Find(primary.TableName);
            DbTableInfoBuilder foreignTable = builder.Find(foreign.TableName);

            MemberInfo[] primaryKeyMembers =
                GetMembers(
                    primaryTable.EntityType,
                    primary.PropertyNames);

            MemberInfo[] foreignKeyMembers =
                GetMembers(
                    foreignTable.EntityType,
                    foreign.PropertyNames);

            IKeyInfo primaryKeyInfo =
                EnsureKey(
                    primaryKeyMembers,
                    true,
                    primaryTable);

            IKeyInfo foreignKeyInfo =
                EnsureKey(
                    foreignKeyMembers,
                    false,
                    foreignTable);

            IRelationContraint[] relationConstraints =
                new IRelationContraint[primaryKeyMembers.Length];

            for (int i = 0; i < relationConstraints.Length; i++)
            {
                relationConstraints[i] =
                    new RelationConstraint(primaryKeyMembers[i], foreignKeyMembers[i]);
            }

            Delegate primaryToForeignConverter =
                CreateConverter(
                    PrimaryToForeignConverterMethod,
                    primaryKeyInfo,
                    foreignKeyInfo,
                    relationConstraints);

            Delegate foreignToPrimaryConverter =
                CreateConverter(
                    ForeignToPrimaryConverterMethod,
                    primaryKeyInfo,
                    foreignKeyInfo,
                    relationConstraints);

            builder.Register(
                new DbRelationInfo(
                    primaryTable:               primary.TableName,
                    primaryKeyInfo:             primaryKeyInfo,
                    primaryToForeignConverter:  primaryToForeignConverter,
                    foreignTable:               foreign.TableName,
                    foreignKeyInfo:             foreignKeyInfo,
                    foreignToPrimaryConverter:  foreignToPrimaryConverter,
                    cascadedDelete:             associationInfo.CascadedDelete));
        }
Example #3
0
        public void Configure(AssociationInfo associationInfo, DbSchemaBuilder builder)
        {
            var primary = associationInfo.PrimaryTable;
            var foreign = associationInfo.ForeignTable;

            DbTableInfoBuilder primaryTable = builder.Find(primary.TableName);
            DbTableInfoBuilder foreignTable = builder.Find(foreign.TableName);

            MemberInfo[] primaryKeyMembers = 
                GetMembers(
                    primaryTable.EntityType,
                    primary.PropertyNames);

            MemberInfo[] foreignKeyMembers =
                GetMembers(
                    foreignTable.EntityType,
                    foreign.PropertyNames);

            IKeyInfo primaryKeyInfo = 
                EnsureKey(
                    primaryKeyMembers,
                    true,
                    primaryTable);

            IKeyInfo foreignKeyInfo = 
                EnsureKey(
                    foreignKeyMembers,
                    false,
                    foreignTable);

            IRelationContraint[] relationConstraints =
                new IRelationContraint[primaryKeyMembers.Length];

            for (int i = 0; i < relationConstraints.Length; i++)
            {
                relationConstraints[i] =
                    new RelationConstraint(primaryKeyMembers[i], foreignKeyMembers[i]);
            }

            Delegate primaryToForeignConverter =
                CreateConverter(
                    PrimaryToForeignConverterMethod,
                    primaryKeyInfo,
                    foreignKeyInfo,
                    relationConstraints);

            Delegate foreignToPrimaryConverter =
                CreateConverter(
                    ForeignToPrimaryConverterMethod,
                    primaryKeyInfo,
                    foreignKeyInfo,
                    relationConstraints);

            builder.Register(
                new DbRelationInfo(
                    primaryTable:               primary.TableName,
                    primaryKeyInfo:             primaryKeyInfo,
                    primaryToForeignConverter:  primaryToForeignConverter,
                    foreignTable:               foreign.TableName,
                    foreignKeyInfo:             foreignKeyInfo,
                    foreignToPrimaryConverter:  foreignToPrimaryConverter,
                    cascadedDelete:             associationInfo.CascadedDelete)); 
        }