コード例 #1
0
        public static void AddTypeConstraint(
            EdmModel database,
            EntityType entityType,
            EntityType principalTable,
            EntityType dependentTable,
            bool isSplitting)
        {
            DebugCheck.NotNull(principalTable);
            DebugCheck.NotNull(dependentTable);
            DebugCheck.NotNull(entityType);

            var foreignKeyConstraintMetadata
                = new ForeignKeyBuilder(
                      database, String.Format(
                          CultureInfo.InvariantCulture,
                          "{0}_TypeConstraint_From_{1}_To_{2}",
                          entityType.Name,
                          principalTable.Name,
                          dependentTable.Name))
                {
                PrincipalTable = principalTable
                };

            dependentTable.AddForeignKey(foreignKeyConstraintMetadata);

            if (isSplitting)
            {
                foreignKeyConstraintMetadata.SetIsSplitConstraint();
            }
            else
            {
                foreignKeyConstraintMetadata.SetIsTypeConstraint();
            }

            foreignKeyConstraintMetadata.DependentColumns = dependentTable.Properties.Where(c => c.IsPrimaryKeyColumn);

            //If "DbStoreGeneratedPattern.Identity" was copied from the parent table, it should be removed
            dependentTable.Properties.Where(c => c.IsPrimaryKeyColumn).Each(c => c.RemoveStoreGeneratedIdentityPattern());
        }
コード例 #2
0
        public static void AddTypeConstraint(
            EdmModel database,
            EntityType entityType,
            EntityType principalTable,
            EntityType dependentTable,
            bool isSplitting)
        {
            ForeignKeyBuilder foreignKeyBuilder = new ForeignKeyBuilder(database, string.Format((IFormatProvider)CultureInfo.InvariantCulture, "{0}_TypeConstraint_From_{1}_To_{2}", (object)entityType.Name, (object)principalTable.Name, (object)dependentTable.Name))
            {
                PrincipalTable = principalTable
            };

            dependentTable.AddForeignKey(foreignKeyBuilder);
            if (isSplitting)
            {
                foreignKeyBuilder.SetIsSplitConstraint();
            }
            else
            {
                foreignKeyBuilder.SetIsTypeConstraint();
            }
            foreignKeyBuilder.DependentColumns = dependentTable.Properties.Where <EdmProperty>((Func <EdmProperty, bool>)(c => c.IsPrimaryKeyColumn));
            dependentTable.Properties.Where <EdmProperty>((Func <EdmProperty, bool>)(c => c.IsPrimaryKeyColumn)).Each <EdmProperty>((Action <EdmProperty>)(c => c.RemoveStoreGeneratedIdentityPattern()));
        }