using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
public static void Main()
using (var context = new EntityContext())
for (int i = 0; i < 5; i++)
context.Customers.Add(new Customer() { Code = "Original_" + i, Email = "Original_" + i, FirstName = "Original_" + i, LastName = "Original_" + i });
var customers1 = context.Customers.WhereBulkContains(new List<int> {999999});
FiddleHelper.WriteTable("1 - WhereBulkContains + Default Key", customers1);
var customers2 = context.Customers.WhereBulkContains(new List<int> {999999}, x => x.CustomerID);
FiddleHelper.WriteTable("2 - WhereBulkContains + Specified Key", customers2);
var customers3 = context.Customers.BulkRead(new List<int> {999999});
FiddleHelper.WriteTable("3 - BulkRead + Default Key", customers3);
var customers4 = context.Customers.BulkRead(new List<int> {999999}, x => x.CustomerID);
FiddleHelper.WriteTable("4 - BulkRead + Specified Key", customers4);
public class FixInterceptor : Microsoft.EntityFrameworkCore.Diagnostics.DbCommandInterceptor
public class EntityContext : DbContext
using (var context = new EntityContext())
context.Database.EnsureCreated();
public DbSet<Customer> Customers { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
optionsBuilder.UseSqlServer(new SqlConnection(FiddleHelper.GetConnectionStringSqlServer())).AddInterceptors(new FixInterceptor());
base.OnConfiguring(optionsBuilder);
public int CustomerID { get; set; }
public string Code { get; set; }
public string Email { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }