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())
List<Customer> customers = new List<Customer>();
customers.Add(new Customer { Name = "ZZZ Projects", MaximumRequestPerDay = 100 });
customers.Add(new Customer { Name = "Jonathan Magnan" });
context.BulkInsert(customers, options => options.LegacyIncludeGraph = true);
FiddleHelper.WriteTable("BulkInsert + LegacyIncludeGraph insert the value is specified, otherwise the default value", context.Customers.AsNoTracking());
public class EntityContext : DbContext
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
optionsBuilder.UseSqlServer(new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()));
base.OnConfiguring(optionsBuilder);
protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.Entity<Customer>().Property(x => x.MaximumRequestPerDay).HasDefaultValueSql("50");
base.OnModelCreating(modelBuilder);
public DbSet<Customer> Customers { get; set; }
public int CustomerID { get; set; }
public string Name { get; set; }
public int MaximumRequestPerDay { get; set; }