Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Shorter Readable query in LINQ

$
0
0

Hello, I have created 2 queries that yield the same results, one is not very readable but is shorter:

var ppls = db.ProjectMembers
.Where(f => f.Project.ProjectStatusSet.Status == "Active" && f.IsContact == true)
                .Select(z => z.Person).GroupBy(p => p.Id)
                .Select(grp => grp.FirstOrDefault())
                .OrderBy(t => t.Name)
                .ToList();

and the other is readable but longer:

 var ppls =
                (from ppl in db.People
                 join pm in db.ProjectMembers
                     on ppl.Id equals pm.ProjectMember_Person
                 join p in db.Projects
                     on pm.ProjectMember_Project equals p.Id
                 join pss in db.ProjectStatusSets
                     on p.Project_ProjectStatus equals pss.Id
                 where pss.Status == "Active" && pm.IsContact == true
                 select ppl
                ).GroupBy(p => p.Id).Select(grp => grp.FirstOrDefault()).OrderBy(t => t.Name).ToList();

How can I make this readable and concise?


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>