0

I can't figure out how to write this query in Linq:

select ic.icCategory, d.domHosting, d.domCode  
  from Domains d join Image_Categories ic 
    on ( d.domCode = ic.icDomainCode )
      where d.domCode = 'code'

Can anyone help?

Thanks

3 Answers 3

2

if you have proper foreign key constraints in your database, there is no need to do all the plumbing on the join yourself. linq-sql creates these also in your classes! That is the beauty of an orm, otherwise you are just writing sql in a different syntax.

You can do

Var x = from i in db.Image_categoriees
    Where i.domain.domcode == 'code'
    Select new { i.icCategory, i.domain.domcode, i.domain.domhosting}
Sign up to request clarification or add additional context in comments.

1 Comment

Thx. I encourage you to switch to the more OO side, i think it is easier to read and maintain...
1

Try something like this:

var result =
    from d in dbContext.Domains
    join ic in dbContext.Image_Categories on d.domCode equals ic.icDomainCode
    where d.domCode == 'code'
    select new { ic.icCategory, d.domHosting, d.domCode }

There is some more information about the Query Expression Syntax Join Operators and some examples here:

http://msdn.microsoft.com/en-us/library/bb896266.aspx

Comments

0
from Domains d join Image_Categories ic  on d.domCode equals ic.icDomainCode
where d.domCode = 'code'
select ic.icCategory, d.domHosting, d.domCode  

2 Comments

-1 This code won't compile. If you make the necessary corrections I will rescind the downvote.
Keep your stupid downvote. It's close enough to clarify the proper functionality. If really think that justifies a downvote, so be it.

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.