1

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'"

2 Answers 2

5

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. ;)

Sign up to request clarification or add additional context in comments.

2 Comments

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!
@Andomar: That's actually f'n brilliant. +1, and it's not even my answer.
3

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'

1 Comment

yes but i will be doing multiple joins so this solution will not work once i add that. sorry, i should have clarified

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.