views:

15

answers:

1

I am taking the values from a search form in my application to build a dynamic query:

string queryString = @"SELECT VALUE USERS FROM ProjectDBEntities.Users AS Users 
WHERE ";

There are two tables in the database, Users and Photo, table Photo has a column UserId that links to the Users table. A one to many relationship exists between Users and Photo.

After some iteration through the form values and adding System.Data.Objects.ObjectParameter values, I end up with following query:

SELECT VALUE USERS FROM ProjectDBEntities.Users AS Users 
WHERE Users.CountryId = 2

Then I have this code:

System.Data.Objects.ObjectQuery<Users> usersQuery =
                new System.Data.Objects.ObjectQuery<Users>(queryString, _db);

The usersQuery object does not contain the Image data for each Users. In my View I can iterate through the Users.Image but the Image count is always zero. Do I have to include or attach the Image data somewhere? How?

A: 

Just add an .Include() for the image property:

System.Data.Objects.ObjectQuery<Users> usersQuery =
            new System.Data.Objects.ObjectQuery<Users>(queryString, _db).Include("Image");
Craig Stuntz