I use EF 4 and C#.
I have a query like:
var contentsAuthor = from c in context.CmsContents
join a in context.CmsAuthors on c.AuthorId equals a.AuthorId
where a.UserId == userGuid
select new
{
c.Title,
c.ContentId
};
I would like rewrite it in Linq with Lambda Expression.
My questions:
- How to rewrite it?
- What is the appropriate name for my query syntax and the new with Linq and Lambda (query expression and Linq to Entities???). Please give me a hit on this point I’m confused.
Notes: probably the title for this question is not appropriate, let me know I will improve it
Thanks guys for your help on this!
The lambda expression should look like:
Both yours and this version are LINQ queries. This one uses lambdas directly whereas your version uses syntactic sugar available in C#. They are the same. LINQ-to-Entities have nothing to do with this.
Anyway if you are using LINQ-to-Entities your
CmsContentshould haveAuthorproperty and your query would reduce to:The LINQ-to-Entities provider will make join for you when translating expression tree to SQL query.