Próbuję użyć funkcji Multimapping z dapper, aby zwrócić listę ProductItems i powiązanych klientów.Prawidłowe użycie Multimapping w Dapper
[Table("Product")]
public class ProductItem
{
public decimal ProductID { get; set; }
public string ProductName { get; set; }
public string AccountOpened { get; set; }
public Customer Customer { get; set; }
}
public class Customer
{
public decimal CustomerId { get; set; }
public string CustomerName { get; set; }
}
Mój kod elegancki jest następujący
var sql = @"select * from Product p
inner join Customer c on p.CustomerId = c.CustomerId
order by p.ProductName";
var data = con.Query<ProductItem, Customer, ProductItem>(
sql,
(productItem, customer) => {
productItem.Customer = customer;
return productItem;
},
splitOn: "CustomerId,CustomerName"
);
Działa to dobrze, ale wydaje mi się, aby dodać pełną listę kolumn do parametru splitOn aby powrócić wszystkie właściwości klientów. Jeśli nie dodaję "CustomerName", zwróci ona wartość null. Brakuje mi zrozumienia podstawowej funkcjonalności funkcji multimapping. Nie chcę za każdym razem dodawać pełnej listy nazw kolumn.
jak właściwie wyświetlić obie tabele w datagridview? mały przykład będzie bardzo doceniany. –