using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.Data.SqlClient;
public static void Main()
DapperPlusManager.Entity<Product>()
.Identity(x => x.ProductID)
x.MergeMatchedAndOneNotConditionExpression = y => new { y.Name };
var products = new List<Product>();
products.Add(new Product() { ProductID = 13, Name = "Dapper Plus", Description = @"Use <a href=""https://dapper-plus.net/"" target=""_blank"">Dapper Plus</a> to extend your IDbConnection with high-performance bulk operations." });
products.Add(new Product() { ProductID = 66, Name = "C# Eval Expression", Description = @"Use <a href=""https://eval-expression.net/"" target=""_blank"">C# Eval Expression</a> to compile and execute C# code at runtime." });
products.Add(new Product() { ProductID = 99, Name = "Entity Framework Extensions", Description = @"Use <a href=""https://entityframework-extensions.net/"" target=""_blank"">Entity Framework Extensions</a> to extend your DbContext with high-performance bulk operations." });
var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServer());
connection.CreateTable<Product>();
connection.BulkInsert(products.Take(2));
FiddleHelper.WriteTable("1 - Product Before", connection.Query<Product>("SELECT * FROM Product"));
products[0].Name += " (New Name)";
products[0].Description = "The description for product[0] is modified as the name is different";
products[1].Description = "The description for product[1] is not modified as the name is the same";
connection.BulkMerge(products);
FiddleHelper.WriteTable("2 - Product After", connection.Query<Product>("SELECT * FROM Product"));
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ProductID { get; set; }
public string Name { get; set; }
public string Description { get; set; }