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 goodResult = new List<EzEmployee>();
goodResult.AddRange(data.Where(x=> x.Status.Equals("ACTIVE", StringComparison.CurrentCultureIgnoreCase))
.GroupBy(x=> x.EmailAddress)
.Select(g=>g.FirstOrDefault()).ToList());
var activeEmailList = goodResult.Select(x => x.EmailAddress).ToList();
goodResult.AddRange(data.Where(x => !activeEmailList.Contains(x.EmailAddress)
&& x.Status.Equals("INACTIVE", StringComparison.CurrentCultureIgnoreCase))
.GroupBy(x => x.EmailAddress)
.Select(g=>g.FirstOrDefault()).ToList());
Console.WriteLine("========= Foreach List =========");
Console.WriteLine("Exec total Milliseconds:" + watch.ElapsedMilliseconds);
Console.WriteLine("Exec total count:" + goodResult.Count());
public int Id { get; set; }
public string RowId { get; set; }
public string EmailAddress { get; set; }
public string Status { get; set; }