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