4
我有大约20列的表。我想要获得每个ID都具有最大“版本”列的所有列的行。实体框架选择一列中具有最大值的行
ID | Version | Other data
--------+---------+----------
1 | 1 | text1
1 | 2 | text2
1 | 3 | text3
2 | 1 | text1
3 | 1 | text1
3 | 2 | text2
我要的是:
ID | Version | Other data
--------+---------+----------
1 | 3 | text3
2 | 1 | text1
3 | 2 | text2
我知道如何实现它的SQL。我不知道如何在实体框架上实现这一点。特别是如果我有20列。
我写的,我有20列。你正在创建新的匿名类型。我想要连接到原始行的原始类型到数据库。 – Marcin1199 2015-03-19 12:02:32
我创造了我自己的,但它是非常缓慢的 context.TableName.GroupBy(X => x.ID) .SelectMany( 组=> group.Where( R => r.version == group.Max( x => x.version)) 。选择(r => r)); – Marcin1199 2015-03-19 12:06:43