Closed john-aaron-owens closed 3 years ago
The column alias in your SQL query is not correct. You need to change from “Order_OrderId” to “Orders_OrderId”. Essentially you need to make the alias match the name of the property name on your object which is plural “Orders”.
Could someone take a look and tell me why Order.OrderDetails is returning as null after the map. The sql works and there is order details in the database. I can get nesting working for the 1 level, but not 2.
btw - I may have a typo as I had to rename the class and fields but the sql does work and no exceptions are being thrown. It just can't find the data which is nested a the 2nd level.
public class Project { public long ProjectId { get; set; } public IEnumerable Orders { get; set; }
}
public class Order { public long OrderId { get; set; } public IEnumerable OrderDetails{ get; set; }
}
public class OrderDetail { public long OrderDetailId { get; set; } }
SELECT p.Project_ID AS ProjectId o.Order_ID AS Order_OrderId, od.Order_Detail_ID AS Order_OrderDetail_OrderDetailId, FROM Project AS p LEFT JOIN Order AS o ON p.Order_ID = o.Order_ID LEFT JOIN OrderDetail AS od ON o.Order_Detail_ID = od.Order_Detail_ID ";