Development & Training in .NET
Retrieving Data by Using LINQ to Entities
A simple snippet that let’s you know how to retrieve data by using LINQ to Entities. Just follow it through, I guess it’s self-explanatory.
// Retrieving Data by using LINQ to Entities
using (EMSEntities context = new EMSEntities())
{
ObjectQuery<Order> orders = context.Orders;
IQueryable<Order> query = from c in orders where
c.OrderID == 1 select c;
List<Order> results = query.ToList();
string orderID = results[0].OrderID.ToString();
string orderDate = results[0].OrderDate.ToString();
Debug.WriteLine(String.Format("Order ID = {0}, " +
" Order Date = {1}", orderID, orderDate));
EntityCollection<OrderDetail> details =
results[0].OrderDetails;
Debug.WriteLine(String.Format(
"Order Detail Count = {0}", details.Count));
}
Incoming search terms:
| Print article | This entry was posted by Felix on July 13, 2011 at 6:23 pm, and is filed under .NET Training, .NET Training Chennai, .NET Training in Chennai, For the love of C# .NET. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |

