1

I have a table called Students and a table called Majors, Students and Majors are joined by MajorId I have set this relationship already and have set the foreign key in the schema. When I access my Student object how can I return the MajorName column (this comes from the Majors table)? The only options I have in intellisense is Major_1, Major_1Reference, MajorId .

anthonypliu
  • 12,179
  • 28
  • 92
  • 154

2 Answers2

2

Major_1 should be a navigation property leading to the appropriate Major entry, so you should be able to access the Major's properties like this:

from s in ctx.Students
select s.Major_1.MajorName
StriplingWarrior
  • 151,543
  • 27
  • 246
  • 315
0

You can use linq join statement like this to make query on the two tables...

var q = from s in Students
        join m in Majors on s.MajorId  equals m.MajorId 
        select new { m.MajorName }; 
Amol Kolekar
  • 2,307
  • 5
  • 30
  • 45