예제 #1
0
        private static void MoveForeignKeyConstraint(
            EntityType fromTable,
            EntityType toTable,
            ForeignKeyBuilder fk)
        {
            fromTable.RemoveForeignKey(fk);
            if (fk.PrincipalTable == toTable && fk.DependentColumns.All <EdmProperty>((Func <EdmProperty, bool>)(c => c.IsPrimaryKeyColumn)))
            {
                return;
            }
            IList <EdmProperty> dependentColumns = ForeignKeyPrimitiveOperations.GetDependentColumns((IEnumerable <EdmProperty>)fk.DependentColumns.ToArray <EdmProperty>(), (IEnumerable <EdmProperty>)toTable.Properties);

            if (ForeignKeyPrimitiveOperations.ContainsEquivalentForeignKey(toTable, fk.PrincipalTable, (IEnumerable <EdmProperty>)dependentColumns))
            {
                return;
            }
            toTable.AddForeignKey(fk);
            fk.DependentColumns = (IEnumerable <EdmProperty>)dependentColumns;
        }
예제 #2
0
        private static void CopyForeignKeyConstraint(
            EdmModel database,
            EntityType toTable,
            ForeignKeyBuilder fk,
            Func <EdmProperty, EdmProperty> selector = null)
        {
            ForeignKeyBuilder foreignKeyBuilder = new ForeignKeyBuilder(database, ((IEnumerable <INamedDataModelItem>)database.EntityTypes.SelectMany <EntityType, ForeignKeyBuilder>((Func <EntityType, IEnumerable <ForeignKeyBuilder> >)(t => t.ForeignKeyBuilders))).UniquifyName(fk.Name))
            {
                PrincipalTable = fk.PrincipalTable,
                DeleteAction   = fk.DeleteAction
            };

            foreignKeyBuilder.SetPreferredName(fk.Name);
            IList <EdmProperty> dependentColumns = ForeignKeyPrimitiveOperations.GetDependentColumns(selector != null ? fk.DependentColumns.Select <EdmProperty, EdmProperty>(selector) : fk.DependentColumns, (IEnumerable <EdmProperty>)toTable.Properties);

            if (ForeignKeyPrimitiveOperations.ContainsEquivalentForeignKey(toTable, foreignKeyBuilder.PrincipalTable, (IEnumerable <EdmProperty>)dependentColumns))
            {
                return;
            }
            toTable.AddForeignKey(foreignKeyBuilder);
            foreignKeyBuilder.DependentColumns = (IEnumerable <EdmProperty>)dependentColumns;
        }