using System.Collections.Generic;
using System.Data.SqlClient;
public int SupplierID {get;set;}
public string SupplierName {get;set;}
public List<Product> Products {get;set;}
public int ProductID {get;set;}
public string ProductName {get;set;}
public static void Main()
List<Supplier> suppliers = new List<Supplier>();
using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServerW3Schools()))
connection.Query("Update OrderDetails set ProductID = 11");
var supplierDictionary = new Dictionary<int, Supplier>();
suppliers = connection.Query<Supplier, Product, Supplier>("Select A.SupplierID, A.SupplierName, B.ProductID, B.ProductName FROM Suppliers as A inner join Products as B on B.SupplierID =A.SupplierID where A.supplierID = 1",
if (!supplierDictionary.TryGetValue(supplier.SupplierID, out supplierEntry))
supplierEntry = supplier;
supplierEntry.Products = new List<Product>();
supplierDictionary.Add(supplier.SupplierID, supplierEntry);
supplierEntry.Products.Add(product);
}, splitOn: "ProductID").Distinct().ToList();
FiddleHelper.WriteTable(suppliers);
FiddleHelper.WriteTable(suppliers.FirstOrDefault().Products);
DapperPlusManager.Entity<Supplier>().Table("Suppliers").Identity(x => x.SupplierID);
DapperPlusManager.Entity<Product>().Table("Products").Identity(x => x.ProductID);
using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServerW3Schools()))
connection.BulkDelete(suppliers.SelectMany(x => x.Products)).BulkDelete(suppliers);
using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServerW3Schools()))
var supplierDictionary = new Dictionary<int, Supplier>();
suppliers = connection.Query<Supplier, Product, Supplier>("Select A.SupplierID, A.SupplierName, B.ProductID, B.ProductName FROM Suppliers as A inner join Products as B on B.SupplierID =A.SupplierID where A.supplierID = 1",
if (!supplierDictionary.TryGetValue(supplier.SupplierID, out supplierEntry))
supplierEntry = supplier;
supplierEntry.Products = new List<Product>();
supplierDictionary.Add(supplier.SupplierID, supplierEntry);
supplierEntry.Products.Add(product);
}, splitOn: "ProductID").Distinct().ToList();
Console.WriteLine("Row count after delete: " + suppliers.Count());