views:

195

answers:

2

Hi!

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!

+1  A: 

This should do the job:

var list = from cd in guideContext.ContentDetail
           where cd.id_contentID == contentID && 
                 cd.Content.id_contentTypeID == contentTypeId
           select cd;
Mehrdad Afshari
I need to check contentTypeID and in your query I don't see this value.
VansFannel
VansFannel: Yeah, I updated that. I'm confused with your relationships. I *think* this should work. If it doesn't, please post the entity structures.
Mehrdad Afshari
Yes, it works! Thank you for your help.
VansFannel
You're welcome ;)
Mehrdad Afshari
+2  A: 

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;
Jakob Christensen