Last post Jan 17, 2018 10:41 AM by Cathy Zou
Jan 03, 2018 11:37 AM|tridip1974|LINK
suppose i have a order and order detail entity. i want to fetch specific order data and its related order detail by EF.
can i use this LINQ query
IEnumerable<Order> order= _ctx.order
.Include(x => x.orderdetails)
.Where(x => x.OrderID== _OrderID).ToList();
does the above code works fine? also tell me how to achieve the same with join also?
also tell me if i need to show specific customer data and customer order and order details then how i need to compose my EF query? help me with code. thanks
Jan 17, 2018 10:41 AM|Cathy Zou|LINK
protected void Page_Load(object sender, EventArgs e)
using (Database3Entities _ctx = new Database3Entities())
//does the above code works fine?
Order orders = (_ctx.Orders.Include("Order_Details").Where(x => x.OrderID == 10250)).SingleOrDefault();
IEnumerable<Order_Detail> details = orders.Order_Details.ToList();
GridView1.DataSource = details;
//also tell me how to achieve the same with join also?
var joinResult = (from ep in _ctx.Orders
join d in _ctx.Order_Details on ep.OrderID equals d.OrderID
where ep.OrderID == 10250
id = ep.OrderID,
CustomerId = ep.CustomerID,
UnitPrice = d.UnitPrice,
Quantity = d.Quantity
GridView2.DataSource = joinResult;
// if i need to show specific customer data and customer order and order details then how i need to compose my EF query? help me with code
var entryPoint = (from ep in _ctx.Customers
join d in _ctx.Orders on ep.CustomerID equals d.CustomerID
join t in _ctx.Order_Details on d.OrderID equals t.OrderID
where ep.CustomerID == "ANATR"
CustomerID = ep.CustomerID,
OrderDate = d.OrderDate,
Quantity = t.Quantity
GridView3.DataSource = entryPoint;