@@ -311,7 +311,7 @@ private void CreateProperties(Entity entity, DatabaseTable tableSchema)
311311
312312 private void CreateRelationships ( EntityContext entityContext , Entity entity , DatabaseTable tableSchema )
313313 {
314- foreach ( var foreignKey in tableSchema . ForeignKeys )
314+ foreach ( var foreignKey in tableSchema . ForeignKeys . OrderBy ( fk => fk . Name ) )
315315 {
316316 // skip relationship if principal table is ignored
317317 if ( IsIgnored ( foreignKey . PrincipalTable , _options . Database . Exclude . Tables ) )
@@ -320,6 +320,12 @@ private void CreateRelationships(EntityContext entityContext, Entity entity, Dat
320320 continue ;
321321 }
322322
323+ if ( IsIgnored ( foreignKey , _options . Database . Exclude . Relationships ) )
324+ {
325+ _logger . LogDebug ( " Skipping Relationship : {name}" , foreignKey . Name ) ;
326+ continue ;
327+ }
328+
323329 CreateRelationship ( entityContext , entity , foreignKey ) ;
324330 }
325331
@@ -748,6 +754,16 @@ private static bool IsIgnored(DatabaseColumn column, IEnumerable<MatchOptions> e
748754 return IsIgnored ( name , excludeExpressions , includeExpressions ) ;
749755 }
750756
757+ private static bool IsIgnored ( DatabaseForeignKey relationship , IEnumerable < MatchOptions > exclude )
758+ {
759+ var table = relationship . Table ;
760+ var name = $ "{ table . Schema } .{ table . Name } .{ relationship . Name } ";
761+ var includeExpressions = Enumerable . Empty < MatchOptions > ( ) ;
762+ var excludeExpressions = exclude ?? [ ] ;
763+
764+ return IsIgnored ( name , excludeExpressions , includeExpressions ) ;
765+ }
766+
751767 private static bool IsIgnored < TOption > ( Property property , TOption options , SharedModelOptions sharedOptions )
752768 where TOption : ModelOptionsBase
753769 {
0 commit comments