morelinq

Getting the MoreLinq MaxBy function to return more than one element

隐身守侯 提交于 2019-12-25 12:44:29
问题 I have a situation in which I have a list of objects with an int property and I need to retrieve the 3 objects with the highest value for that property. The MoreLinq MaxBy function is very convenient to find the single highest, but is there a way I can use that to find the 3 highest? (Not necessarily of the same value). The implementation I'm currently using is to find the single highest with MaxBy, remove that object from the list and call MaxBy again, etc. and then add the objects back into

Distinct()与lambda?

元气小坏坏 提交于 2019-12-23 21:37:26
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 是的,所以我有一个可枚举的,并希望从中获得不同的值。 使用 System.Linq ,当然有一个名为 Distinct 的扩展方法。 在简单的情况下,它可以在没有参数的情况下使用,例如: var distinctValues = myStringList.Distinct(); 好的,但如果我有一个可以指定相等性的可枚举对象,唯一可用的重载是: var distinctValues = myCustomerList.Distinct(someEqualityComparer); equality comparer参数必须是 IEqualityComparer<T> 的实例。 当然,我可以做到这一点,但它有点冗长,而且很有说服力。 我所期望的是一个需要lambda的重载,比如Func <T,T,bool>: var distinctValues = myCustomerList.Distinct((c1, c2) => c1.CustomerId == c2.CustomerId); 任何人都知道是否存在某些此类扩展或某些等效的解决方法? 或者我错过了什么? 或者,有没有一种方法可以指定IEqualityComparer内联(embarass me)? 更新 我找到了Anders

Linq distinct based on two columns

爱⌒轻易说出口 提交于 2019-12-11 03:13:44
问题 I've a requirement where I need to fetch the unique records with same combination in 2 columns. My data would be Like CA(Column A) and CB(Column B) with some data CA CB 1 2 1 2 3 4 5 6 2 1 1 6 1 6 5 1 Let's say, I need to fetch records with value 1 from both the columns which should be unique. So, My End result should be like : 1 2 1 6 5 1 Here I should not get the record 2 , 1 because the combination already exists as 1 , 2 in the first record. Here's the query I've tried : var recentchats =

DistinctBy with two properties in VB.NET

陌路散爱 提交于 2019-12-02 06:55:59
问题 Looking at Select distinct by two properties in a list it is possible to use the DistinctBy extensionmethod with two properties. I tried to convert this to vb.net, but I'm not getting the expected results Test Class: Public Class Test Public Property Id As Integer Public Property Name As String Public Overrides Function ToString() As String Return Id & " - " & Name End Function End Class Test Method: Private Sub RunTest() Dim TestList As New List(Of Test) TestList.Add(New Test() With {.Id = 1

DistinctBy with two properties in VB.NET

好久不见. 提交于 2019-12-02 05:21:26
Looking at Select distinct by two properties in a list it is possible to use the DistinctBy extensionmethod with two properties. I tried to convert this to vb.net, but I'm not getting the expected results Test Class: Public Class Test Public Property Id As Integer Public Property Name As String Public Overrides Function ToString() As String Return Id & " - " & Name End Function End Class Test Method: Private Sub RunTest() Dim TestList As New List(Of Test) TestList.Add(New Test() With {.Id = 1, .Name = "A"}) TestList.Add(New Test() With {.Id = 2, .Name = "A"}) TestList.Add(New Test() With {.Id

MoreLinq maxBy vs LINQ max + where

巧了我就是萌 提交于 2019-11-28 13:46:45
I am using EF5 with the MoreLinq extenstion, while testing my program in production (very big database), I found out that the line: var x = db.TheBigTable.MaxBy(x => x.RecordTime); Takes very long time ( RecordTime is a non-indexed datetime ) Is that because MaxBy always runs on the client side (and firstly gets ALL records from the database)? Here is the signature of the MaxBy extension method : public static TSource MaxBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> selector) { return source.MaxBy(selector, Comparer<TKey>.Default); } It returns the maximal element

MoreLinq maxBy vs LINQ max + where

ⅰ亾dé卋堺 提交于 2019-11-27 07:51:50
问题 I am using EF5 with the MoreLinq extenstion, while testing my program in production (very big database), I found out that the line: var x = db.TheBigTable.MaxBy(x => x.RecordTime); Takes very long time ( RecordTime is a non-indexed datetime ) Is that because MaxBy always runs on the client side (and firstly gets ALL records from the database)? 回答1: Here is the signature of the MaxBy extension method: public static TSource MaxBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource,