Posts

Showing posts with the label dapperdotnet

Dapper.Net One-To-Many mapping

While using Dapper.Net, most common and fundamental scenario is to load the result that form one-to-many relationship. After doing some searching and refactoring the idea multiple times, I get a refactored solution. Scenario Consider a simple customer-order scenario. A customer could have multiple orders, while a order will be associated with only one customer. The models are: public class Customer     {         public String CustomerId { get; set; }         public String CustomerName { get; set; }         public IEnumerable<Order> Orders { get; set; }     } public class Order     {         public string OrderId { get; set; }         public string CustomerId { get; set; }     } The SQL query to fetch both Customer and Order details is, SELECT * FROM Customers c JOIN Orders o ON c.CustomerId = o.CustomerId ORDER BY c.Cus...