我有一个包含 8 个整数值记录的表:
TableChild:
Parent Name int1 int2 int3 int4 int5 int6 int7 int8
a w 1 3 2 0 1 3 4 3
a x 4 5 2 5 3 2 4 6
b y 5 3 5 3 1 1 3 4
b z 4 1 2 4 2 2 4 2
例如,我需要找到“x”的最大值。 例如,我还(单独)需要为父“a”获取整个表中的最高值。
var query = from row in TableChild
where row.Name == x
select new
{
Parent = row.Parent,
Name = row.Name,
status = GetHighestValueOfRowInTableChild,
...
};
返回 { (a,x,6) }
var queryParent = from row in tableParent
where row.Name == a
select new
{
Parent = row.Name,
status = GetHighestValueOfAllChildItemsInTableChild,
...
};
返回{(a,6)}
我玩过 .Max() 并尝试使用表达式,但没有任何运气,因为我可能应该使用多个连接但无法弄清楚它们应该如何交互。
最佳答案
用 int{X} 属性的值创建一个数组,稍后获取数组的最大值
var queryParent = from row in tableParent
where row.Name == a
select new
{
Parent = row.Name,
status =
(new int[]{row.int1,row.int2,row.int3,row.int4,
row.int5,row.int6,row.int7,row.int8}).Max();
...
};
关于c# - Linq-to-Entities,比较不同字段/列中的 int 值并返回最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12351787/