开发者

Convert Linq Query Expression to Method Syntax equivalent

开发者 https://www.devze.com 2023-03-21 21:03 出处:网络
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 exampl

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消