Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Linq Query Always Returns a Result Equal to Zero

$
0
0

The result of my linq query always returns zero when I know that it should return a result larger than zero.

I have two in-memory tables, dtEquipment and dtX; both with identical schema. I want to validate that the value ParentID column of each row in table dtX is found in the equipmentID column of table dtEquipment, OR the value of the ParentID column of each row in table dtX is found in the equipmentID column of table dtX. To put it another way, each ParentID in table dtX must be present in either of the equipmentID columns of either table dtEquipment or dtX.

I have started by merging the two tables into one: dtEquipment.Merge(dtX).  I want iterate through the rows of dtX and determine if the ParentID of each row is present in the equipmentID column of the merged table dtEquipment.

My query result count is zero even when I know that the ParentID is found in the equipmentID column.

DataTable dtEquipment = new DataTable("equipment");
private List<ErrorDescription> parentIDValidated(DataTable dtX, int iErrorRowIndex)
{
    List<ErrorDescription> errors = new List<ErrorDescription>();
    dtEquipment.Merge(dtX);
    for (int i = 0; i < dtX.Rows.Count; i++)
    {
        var results = from row in dtEquipment.AsEnumerable()
                        where row["equipmentID"] == dtX.Rows[i]["ParentID"]
                        select row;
        if (results.Count() == 0)  // <-- results always zero even when the ParentID is contained in the equipmentID column
        {
            ErrorDescription eD = new ErrorDescription(iErrorRowIndex);
            eD.Description = "Invalid ParentID: The Parent ID value must already exist in the Equipment ID column.";
            errors.Add(eD);
        }
    }
    return errors;
}
What am I missing?


Rob E.


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>