using System.Data.SqlClient;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
public static void Main()
using (var context = new EntityContext())
context.Customers.Add(new Customer() { Name ="Customer_A", IsActive = false });
using (var context = new EntityContext())
context.Customers.Add(new Customer() { Name ="Customer_A", IsActive = false });
context.Customers.Add(new Customer() { Name ="Customer_B", IsActive = true });
context.Customers.Add(new Customer() { Name ="Customer_C", IsActive = false });
Console.WriteLine("SaveChanges : ");
Console.WriteLine(e.Message);
Console.WriteLine("SaveChanges InnerException 1: ");
Console.WriteLine(e.InnerException.Message);
Console.WriteLine("SaveChanges InnerException 2 : ");
Console.WriteLine(e.InnerException.InnerException.Message);
using (var context = new EntityContext())
context.Customers.Add(new Customer() { Name ="Customer_A", IsActive = false });
context.Customers.Add(new Customer() { Name ="Customer_B", IsActive = true });
context.Customers.Add(new Customer() { Name ="Customer_C", IsActive = false });
context.BatchSaveChanges();
Console.WriteLine("BatchSaveChanges : ");
Console.WriteLine(e.Message);
public class EntityContext : DbContext
public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServer())
public DbSet<Customer> Customers { get; set; }
public static void CreateTrigger()
using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()))
using (var command = connection.CreateCommand())
CREATE TRIGGER [dbo].[TRIGER_Customer]
AFTER INSERT,DELETE,UPDATE
RAISERROR (N'Custom error!!!!!', -- Message text.
command.ExecuteNonQuery();
public int CustomerID { get; set; }
public string Name { get; set; }
public Boolean IsActive { get; set; }