David Smith

David Smith

  • NA
  • 2k
  • 0

C# Combine Linq

Apr 20 2015 9:48 AM
//Getting the parentid that is listed multiple times in the grandparent table.

var parentCount = (from c in GetGrandparentChildRows(grandparentRow).AsEnumerable()
where Convert.ToInt32(c["ParentId"]) == parent.ParentId
select c).Count();
 
 
//If the parent id count is greater than one, then there are multiple parent ids of the same number parent or number, which is valid
if(parentCount > 1)
{
 
Choose the lowest/min grandparent id integer or record with the of same parent id
var lowestGrandparentIdRecord = (from c in GetGrandparentChildRows(grandparentRow).AsEnumerable()
where Convert.ToInt32(c["ParentId"]) == parent.ParentId
select c).Min(s => s["GrandparentId"]);
 
Select Grandparent Name, Address, and GrandparentID
var grandparentRecord = from c in GetGrandparentChildRows(grandparentRow).AsEnumerable()
where Convert.ToInt32(c["GrandparentId"]) == Convert.ToInt32(lowestGrandparentIdRecord)
select c;

}