using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Threading.Tasks;
using Microsoft.Data.SqlClient;
public static async Task Main()
var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServer());
connection.CreateTable<Products>();
var seedProducts = new List<Products>();
seedProducts.Add(new Products() { Name = "Dapper Plus", CategoryID = 1, Description = @"Use <a href=""https://dapper-plus.net/"" target=""_blank"">Dapper Plus</a> to extend your IDbConnection with high-performance bulk operations." });
seedProducts.Add(new Products() { Name = "C# Eval Expression", CategoryID = 2, Description = @"Use <a href=""https://eval-expression.net/"" target=""_blank"">C# Eval Expression</a> to compile and execute C# code at runtime." });
seedProducts.Add(new Products() { Name = "Entity Framework Extensions", CategoryID = 1, Description = @"Use <a href=""https://entityframework-extensions.net/"" target=""_blank"">Entity Framework Extensions</a> to extend your DbContext with high-performance bulk operations." });
connection.BulkInsert(seedProducts);
var sql = "SELECT * FROM Product WHERE CategoryID = @categoryID";
var products = (await GetProducts(connection, sql));
foreach(var product in products)
Console.WriteLine($"ProductID: {product.ProductID}; Namse: {product.Name}; Desc: {product.Description}");
public static Task<IEnumerable<Products>> GetProducts(SqlConnection connection, string sql)
return connection.QueryAsync<Products>(sql, new { categoryID = 1 });
public class Products : LookUp
public int CategoryID { get; set; }
public abstract class LookUp : BaseEntity
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ProductID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public abstract class BaseEntity { }