views:

98

answers:

1

Hi,

I have a database which consists of the following:

** Table 1 **

  • Id (PK)
  • Field1

** Table 2 **

  • Id (PK)
  • Field2

** Link Table **

  • Table1Id (FK)
  • Table2Id (FK)

The problem is, I cannot access Table 2 from Table 1, even though the relationship exists in the database.

For example, the following should be possible:

var Results = from c in DataContext.Table1
              where c.Table2.Field2 == "Test"
              select c;

However, "c.Table2.Field2" is not available for some reason - all I get for "c.Table2." is the following (among the standard any<>, where<> et al):

  • RelationshipName
  • RelationshipSet
  • SourceRoleName
  • TargetRoleName

So obviously something is screwy somewhere, but I cannot work out what!

Both tables exist in the Entity Schema, and have a valid relationship between them.

+1  A: 

The reason that c.Table2.Field2 is not available is that c.Table2 doesn't have a property called Field2. c.Table2 is a list of entities which have that property, not an instance of that entity. It's not clear what your intention is here, but I think you want:

var Results = from c in DataContext.Table1
              where c.Table2.Any(t2 => t2.Field2 == "Test")
              select c;
Craig Stuntz