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);
gvrelprd.DataBind();
Pirate11
Member
2 Points
6 Posts
Retrieve list of images from a HAS-A relationship model...
Mar 01, 2012 09:27 AM|LINK
Hello.
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:
Thank You.
(Vaya Infotech)
texx
Contributor
2412 Points
415 Posts
Re: Retrieve list of images from a HAS-A relationship model...
Mar 01, 2012 05:16 PM|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;