tags:

views:

380

answers:

1

I must have missed something in my LINQ training. In Linq to SQL using c#, I want to query two tables, one with the foreign key to the other, and pass two parameters, one for each table.

IN SQL, it is something simple like

Select Value from Table1 T1 
INNER JOIN Table2 T2
On T1.DefID = T2.ID
Where T1.PollID = 1 
AND T2.Name = 'Question'

in LINQ, I get stuck!

var q = from t1 in dc.Table1
        join t2 in dc.Table2
        on t1.DefID equals t2.ID
        into newGroup
        where t1.PollID == 1   // here's where I get stuck!
        // how do I query t2?
        select newGroup;

Is my approach wrong? Thanks in advance.

+2  A: 
var q = from t1 in dc.Table1
    join t2 in dc.Table2
    on t1.DefID equals t2.ID
    where t1.PollID == 1 &&
    t2.Name == "Question"
    select new {
        Alias1 = t1.FieldName,
        Alias2 = t2.FieldName
    };
quinnapi
Ash Machine