Skip to content

Commit d6d9ac6

Browse files
(GH-652) Cleanup foreign key helper
1 parent ed6d68f commit d6d9ac6

File tree

2 files changed

+9
-24
lines changed

2 files changed

+9
-24
lines changed

src/DotNetToolkit.Repository/Configuration/Conventions/Internal/ForeignKeyConventionHelper.cs

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -71,32 +71,17 @@ private static Result GetForeignKeyPropertyInfosCore(Type sourceType, Type targe
7171
return null;
7272
}
7373

74-
// if left is null, its probably because there is no bi-directional nav properties in both types
75-
PropertyInfo[] leftKeysToJoinOn = null;
7674
var leftNavPi = foundInSource ? adjacentNavPropertyInfo : foreignNavPropertyInfo;
77-
if (leftNavPi != null)
78-
{
79-
var leftPiType = leftNavPi.PropertyType.GetGenericTypeOrDefault();
80-
leftKeysToJoinOn = foundInSource
81-
? foreignKeyPropertyInfos
82-
: PrimaryKeyConventionHelper.GetPrimaryKeyPropertyInfos(leftPiType);
83-
}
75+
var leftKeysToJoinOn = foundInSource
76+
? foreignKeyPropertyInfos
77+
: PrimaryKeyConventionHelper.GetPrimaryKeyPropertyInfos(
78+
leftNavPi.PropertyType.GetGenericTypeOrDefault());
8479

85-
PropertyInfo[] rightKeysToJoinOn = null;
8680
var rightNavPi = foundInSource ? foreignNavPropertyInfo : adjacentNavPropertyInfo;
87-
if (rightNavPi != null)
88-
{
89-
var rightPiType = rightNavPi.PropertyType.GetGenericTypeOrDefault();
90-
rightKeysToJoinOn = foundInSource
91-
? PrimaryKeyConventionHelper.GetPrimaryKeyPropertyInfos(rightPiType)
92-
: foreignKeyPropertyInfos;
93-
}
94-
// might be doing a backgward tarversal, which is the only reason why
95-
// left might have something but the right side wont
96-
else if (leftNavPi != null)
97-
{
98-
rightKeysToJoinOn = foreignKeyPropertyInfos;
99-
}
81+
var rightKeysToJoinOn = foundInSource
82+
? PrimaryKeyConventionHelper.GetPrimaryKeyPropertyInfos(
83+
rightNavPi.PropertyType.GetGenericTypeOrDefault())
84+
: foreignKeyPropertyInfos;
10085

10186
return new Result(leftNavPi, leftKeysToJoinOn, rightNavPi, rightKeysToJoinOn);
10287
}

test/DotNetToolkit.Repository.Test/Tests/ForeignKeyConventionHelperTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void FindForeignKeysFromSourceOneDirection()
9292
Assert.NotNull(result);
9393

9494
Assert.Null(result.LeftNavPi);
95-
Assert.Null(result.LeftKeysToJoinOn);
95+
Assert.Equal(nameof(TableI.TableJId), result.LeftKeysToJoinOn[0].Name);
9696

9797
Assert.Equal(rightPi, result.RightNavPi);
9898
Assert.Equal(nameof(TableJ.Id), result.RightKeysToJoinOn[0].Name);

0 commit comments

Comments
 (0)