views:

124

answers:

2

I have a simple table structure

Images(image_id, image_library_id,...)

Links(link_id, image_id, link_component_code...)

I am trying to perform a simple query using LINQ

var q = from i in Images where i.Link.link_component_code = "x" select i;

However the intellisense in LINQPad doesn't provide the "Link" object in

where i.Link.link_component_code

instead I only get a "Links" object, which is an EntitySet and doesn't go on to list the table fields just methods such as Add, Select, Where etc

However if I do it the other way around

var q = from l in Links where l.Image.image_library_id = 1234 select l;

It works as expected

What is this EntitySet and where am I going wrong?

+1  A: 

The way your relationship is set up, each image as 0 or more links (many links). The Links property of an Image is a queryable collection of the related link records.

Try this where clause

where i.Links.Any(link => link.link_component_code == "x")
David B
A: 

Is there more than one link per image? If not, constrain the image_id field in the Links table to be unique. Then you should get the results you expect.