using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using Microsoft.Data.SqlClient;
public static void Main()
using (var context = new EntityContext())
context.Database.EnsureCreated();
using (var context = new EntityContext())
context.Customers.Add(new Customer() { Name ="Customer1", Country = "UK" });
context.Customers.Add(new Customer() { Name ="Customer2", Country = "USA" });
context.Customers.Add(new Customer() { Name ="Customer3", Country = "USA" });
context.BulkSaveChanges();
using (var context = new EntityContext())
var query = context.Customers.GroupBy(a=>a.Name).Select(p=>p.First());
var list = query.ToList();
FiddleHelper.WriteTable(list);
System.Console.WriteLine(list.Count());
System.Console.WriteLine(query.Count());
public class EntityContext : DbContext
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
optionsBuilder.UseSqlServer(new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()));
base.OnConfiguring(optionsBuilder);
public DbSet<Customer> Customers { get; set; }
public int ID { get; set; }
public string Name { get; set; }
public string Country { get; set; }