views:

1442

answers:

2

how do i change this to linq to sql?

select * from ratesSchedule as rs
    inner join userdetails as ud on rs.sid = ud.sid
    and rs.tabletype = 'd'

i got this far

var results = from rs in db.ratesSchedule
              join ud in db.userdetails on rs.sid equals ud.sid

but i can't figure out how to add the "and rs.tabletype='d'"

+1  A: 

You should be able to just put it in the WHERE part of the statement, since you aren't joining on a condition other than a comparison to a constant field on the table:

var results = from rs in db.ratesSchedule
              join ud in db.userdetails on rs.sid equals ud.sid
              where rs.tabletype = 'd'
casperOne
yes but i will be doing multiple joins so this solution will not work once i add that. sorry, i should have clarified
jorsh1
+3  A: 

If you'd like to do it without where clause, try this:

var results = from rs in db.ratesSchedule
              join ud in db.userdetails on 
                  new { rs.sid, rs.tabletype } equals 
                  new { ud.sid, tabletype = "d" }

Personally I'd stick to SQL in this case, since LINQ isn't even easier to read. ;)

Andomar
this was exactly what i was trying to do but with 'd' (a character type) and it wouldn't work. guess i should have tried "d". thanks!
jorsh1
@Andomar: That's actually f'n brilliant. +1, and it's not even my answer.
casperOne