VansFannel
VansFannel

Reputation: 45961

Linq and a select with two tables

I want to make this select using linq:

Select cd.name from Content c, ContentDetail cd
where c.id_contentTypeID = contentTypeId and
      c.id_contentID = contentID and
      cd.id_contentID = c.contentID;

I have done the following but I don't know how to end the query:

var list =
    from c in guideContext.Content, 
        dc in guideContext.ContentDetail
    where c.id_content == contentID &&

    select dc;

Any suggestion?

Thank you!

Upvotes: 1

Views: 3202

Answers (2)

Jakob Christensen
Jakob Christensen

Reputation: 14956

You can do this using a LINQ join as in the following example:

var query = from c in guidecontext.Content
            join cd in guidecontext.ContentDetail
            on c.id_contentID equals cd.id_contendID
            where c.id_contendID = contentId
            && c.contentTypeId = contentTypeId
            select cd.name;

Upvotes: 2

Mehrdad Afshari
Mehrdad Afshari

Reputation: 422242

This should do the job:

var list = from cd in guideContext.ContentDetail
           where cd.id_contentID == contentID && 
                 cd.Content.id_contentTypeID == contentTypeId
           select cd;

Upvotes: 1

Related Questions