using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using Microsoft.Data.SqlClient;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
public static void Main()
using (var context = new EntityContext())
context.Database.EnsureCreated();
List<Customer> list = new List<Customer>()
new Customer() { CustomerID = 1, IdentityInt = 3, Name ="Customer_A" },
new Customer() { CustomerID = 2, IdentityInt = 2, Name ="Customer_B" },
new Customer() { CustomerID = 3, IdentityInt = 4, Name ="Customer_C" }
using (var context = new EntityContext())
context.BulkInsert(list, options => options.InsertKeepIdentity = true);
using (var context = new EntityContext())
FiddleHelper.WriteTable(context.Customers.ToList());
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; }
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int CustomerID { get; set; }
public int IdentityInt { get; set; }
public string Name { get; set; }