I use LINQ, C#, EF4.
I have this query expression in Linq. I need to convert in a equivalen开发者_如何学Got in Method Syntax but I have some doubt on the struction. Could you provide me a good example. Thanks for your help.
var myContentsForAuthor = from c in context.CmsContents
join a in context.CmsAuthors on c.AuthorId equals a.AuthorId
join u in context.aspnet_Users on a.UserId equals u.UserId
orderby c.Title ascending
where u.UserId == myUserGuid && c.IsDeleted == false && c.Title.Contains(nameSearchString)
select c;
Well, this gets complicated because of the transparent identifiers, but something like:
var myContentsForAuthor = context.CmsContents
.Join(context.CmsAuthors,
c => c.AuthorId
a => a.AuthorId,
(c, a) => new { c, a })
.Join(context.aspnet_Users,
z => z.a.UserId,
u => u.UserId,
(z, u) => new { z, u })
.OrderBy(zz => zz.z.c.Title)
.Where(zz => zz.u.UserId == myUserGuid &&
zz.z.c.IsDeleted == false &&
zz.z.c.Title.Contains(nameSearch))
.Select(zz => zz.z.c);
精彩评论