dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.03k stars 4.67k forks source link

DataRelation, possible incorrect order of arguments when calling `FindForeignKeyConstraint` #78628

Open VasilievSerg opened 1 year ago

VasilievSerg commented 1 year ago

Earlier, I found some places in .NET 7 where the order of arguments was incorrect. Here are the issues: #78306, #78212

I found one more place. However, I'm not sure whether this is an error or not.

....
Debug.Assert(ChildTable != null, "On a DataSet, but not on Table. Bad state");
ForeignKeyConstraint? constraint = ChildTable.Constraints.FindForeignKeyConstraint(ChildKey.ColumnsReference, ParentKey.ColumnsReference); // <=
constraint?.CheckConstraint();
....
}

Link to the sources

The FindForeignKeyConstraint method's definition:

ForeignKeyConstraint? FindForeignKeyConstraint(DataColumn[] parentColumns, DataColumn[] childColumns)

Link to the sources

The first parameter is parentColumns and the second one is childColumns. In the method call mentioned above the first argument is ChildKey.ColumnsReference and the second one is the ParentKey.ColumnsReference.

So, the arguments order is Child..., Parent... whereas the parameters order is parent..., child....

Is the reversed order of arguments an error, or is this code fragment correct?

ghost commented 1 year ago

Tagging subscribers to this area: @roji, @ajcvickers See info in area-owners.md if you want to be subscribed.

Issue Details
Earlier, I found some places in .NET 7 where the order of arguments was incorrect. Here are the issues: #78145, #78306, #78212 I found one more place. However, I'm not sure whether this is an error or not. ```csharp .... Debug.Assert(ChildTable != null, "On a DataSet, but not on Table. Bad state"); ForeignKeyConstraint? constraint = ChildTable.Constraints.FindForeignKeyConstraint(ChildKey.ColumnsReference, ParentKey.ColumnsReference); // <= constraint?.CheckConstraint(); .... } ``` [Link to the sources](https://github.com/dotnet/runtime/blob/d099f075e45d2aa6007a22b71b45a08758559f80/src/libraries/System.Data.Common/src/System/Data/DataRelation.cs#L486) The `FindForeignKeyConstraint` method's definition: ```csharp ForeignKeyConstraint? FindForeignKeyConstraint(DataColumn[] parentColumns, DataColumn[] childColumns) ``` [Link to the sources](https://github.com/dotnet/runtime/blob/d099f075e45d2aa6007a22b71b45a08758559f80/src/libraries/System.Data.Common/src/System/Data/ConstraintCollection.cs#L548) The first parameter is `parentColumns` and the second one is `childColumns`. In the method call mentioned above the first argument is `ChildKey.ColumnsReference` and the second one is the `ParentKey.ColumnsReference`. So, the arguments order is `Child...`, `Parent...` whereas the parameters order is `parent...`, `child...`. Is the reversed order of arguments an error, or is this code fragment correct?
Author: VasilievSerg
Assignees: -
Labels: `area-System.Data`
Milestone: -