Yitzhak Weinberg
Yitzhak Weinberg

Reputation: 2562

Distinct By LINQ The Best Way And quickly

want to know unique have by date In other words I will not use it twice one IP address and I would like the field of date What I have done up to now it worked

db.Exposures.DistinctBy(d => d.UserIP).Select(o =>o.ExpouserDate).ToList();

But it took too much time is there a better way Forgiveness for my English and thanks in advance

Upvotes: 0

Views: 201

Answers (1)

Christos
Christos

Reputation: 53958

You could try something like this:

var res = db.Exposures
            .GroupBy(ex => ex.UserIp)
            .Select(gr => gr.Max(x = >x.ExpouserDate));

Upvotes: 3

Related Questions