I have two classes
public class Customer { public int CustomerId { get; set;} public string CustomerName { get; set; } } public class Order { public int OrderId { get; set; } public int CustomerId { get; set; } //BuyerCustomer public int CustomerSecondId { get; set; } //ReceiverCustomer public Customer BuyerCustomer { get; set; } public Customer ReceiverCustomer { get; set; } } Here's my query will look like
SELECT a.*, b.*, c.* FROM dbo.PRODUCTS_ORDER a INNER JOIN dbo.CUSTOMER b ON a.CustomerId=b.CustomerId INNER JOIN dbo.CUSTOMER c ON a.CustomerSecondId=b.CustomerId Dapper Implementation..
List<Order> order= null; order= (List<Order>)dapperconnection.Query<Order, Customer, Customer, Order>(sql, (order, customer1,customer2) => { order.BuyerCustomer = customer1; order.ReceiverCustomer = customer2; return order; }, splitOn: "CustomerId,CustomerSecondId "); The result I'm getting is incomplete, only the RecevierCustomer gets populated while the BuyerCustomer doesn't contain any values at all.
It looks like dapper is confused since i used the CustomerId twice in my query. Is there any workaround with this without having to change my the Customer class?