Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Mar 01, 2012 05:16 PM by texx
Mar 01, 2012 09:27 AM|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 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;