开发者

Entity Framework Return Parent along with child entity as Ieunmerable List

I am new to Entity Framework and had a question i have been stuck on for a while. I have a repository in my DAL to access the data its returning IEnumerable lists for functions defined there. There are two tables involved here table Company and thier Customer_orders please see below for details. I need to return an Ienumerable list for Customer Orders ...which also includes the Customer name. I am able to return everything back for the customer order table but cant get the Customer name from the related table. Is it because I am returning a list of Ienumerable CustomerOrder type? If anyone can provide some help by showing the right code it would be greatly appreciated. Once again I am trying to bind to a grid pulling from the CustomerOrders table but need to also display CustomerName from Customers table.

Table1 (Customers)

compa开发者_如何学编程ny_id

customer_id

customerName

customerAddress

Table 2 (CustomerOrders)

customer_id

product_id

productName

productDesc

This is what I have so far this doesnt pull up any customer Names but pulls the CustomerOrders information

 public IEnumerable<CustomerOrders> GetCustomerOrders(int company_id)
    {
       return context.Customers.Where(c => c.company_id == company_id).First().CustomerOrders.ToList().OrderBy(p => p.ProductName);
}    


How about:

return  context.CustomerOrders
               .Include(o => o.Customer)
               .Where(o => o.customer_id == customer_id);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜