using System.Diagnostics;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Threading.Tasks;
public static void Main()
var setting = new Faker<EzEmployee>()
.RuleFor(p => p.RowId, f => Guid.NewGuid().ToString())
.RuleFor(p => p.EmailAddress, (f, p) => f.Internet.Email())
.RuleFor(p => p.Status, f => f.PickRandom<EzStatus>().ToString());
var emps = setting.Generate(15000);
Console.WriteLine("Total Distinct Email Count:" + emps.Select(x => x.EmailAddress).Distinct().Count());
Console.WriteLine(String.Empty);
public static void GoForeachList(List<EzEmployee> data)
var watch = new Stopwatch();
var result = Enumerable.Empty<EzEmployee>();
var emails = data.GroupBy(x => x.EmailAddress);
result = emails.Select(x => x.FirstOrDefault(y => y.Status.Equals("active", StringComparison.OrdinalIgnoreCase))).Where(x => x != null);
result = result.Concat(emails.Where(x => x.All(y => y.Status.Equals("inactive", StringComparison.OrdinalIgnoreCase))).Select(x => x.First()));
Console.WriteLine("========= Foreach List =========");
Console.WriteLine("Exec total Milliseconds:" + watch.ElapsedMilliseconds);
Console.WriteLine("Exec total count:" + result.Count());
public int Id { get; set; }
public string RowId { get; set; }
public string EmailAddress { get; set; }
public string Status { get; set; }