Last post Mar 01, 2012 06:16 PM by texx
Mar 01, 2012 10:27 AM|Pirate11|LINK
This is my first post. Here is the scenario:
I have a database which has 3 tables:
A FoodItem can have multiple images. I've successfully generated ADO.NET Entity Framework Model for this schema. I can retrieve list of fooditems.
What I want to do is; display list of images of that fooditem below that FoodItem. Much like you have product images in an e-commerce application.
I need to know the EF LINQ query to get these images.
Currently I'm retrieving FoodItems using this query:
otdbEntities dbcontext = new otdbEntities();
Food f = new Food();
f = dbcontext.Foods.Where(ct => ct.FoodId == id).FirstOrDefault();
// id is from querystring
// I'm getting stuck below.
// I don't know how to retrieve Images from FoodHasImages
// I can very easily do it using traditional SQL, but I need to know how to do it using LINQ ?
gvrelprd.DataSource = dbcontext.FoodHasIages.Select(s => s.FoodId == id);
Mar 01, 2012 06:16 PM|texx|LINK
One slight change
gvrelprd.DataSource = dbcontext.FoodHasImages.Where(s => s.FoodId == id).Select(s => s.FoodImage))
If you are using EntityFramework and your relationships are setup properly, you could just
gvrelprd.DataSource = f.FoodImages;