A C# Linq to Sql query that uses SUM, Case When, Group by, outer join, aggregate and defaults -


I am looking for possible solutions and trying it for hours without luck.

I have found an Sql statement that I am trying to put together as a C # LINQ query.

Here is a working SQL:

  select up.UserProfileID, up.FirstName, up.LastName, SUM (case when ul.CompletionDate zero 0 join IsNull (ul.Score, 0) end) up.UserProfileID = ul.UserProfileID dbo.UserLearning ul Left outside up dbo.UserProfile as TotalScore where up.ManagerUserProfileID up.UserProfileID, up.FirstName, We have tried many different ways by up.LastName  but I think that whatever I want or who does not execute successfully, a statement of Ends with  

My current (non-job) code looks like this:

  on PD = db.UserProfiles in db.UserLearnings joining the UL Up.UserProfileID temp.DefaultIfEmpty (New UserLearning () {Score = 0}) As far as up from Jojinul, ul.UserProfileID equals in. ManagerUserProfileID.Equals (empty) group by new {UserProfil Id = up.UserProfileID, FirstName = up.FirstName, LastName = up.LastName, TotalScore = up.UserLearnings.Sum (U = & gt; U.Score)};   

Thanks for any help

Many more efforts After and after the use of Google I finally managed to get a work solution . I hope it will be someone else's work

  var PD = db.UserProfiles.AsEnumerable () .Where (up = & gt; up.ManagerUserProfileID.Equals (zero)) is. Select (top = & gt; new {UserProfileID = up.UserProfileID, first name = above.first name, last name = up.lithname, total score = up user linerning where (ul = & gt; ul. Hasleval & amp; ul.Score HasValue) .efaultIfEmpty () .sum (ul = & gt; ul = null & amp; ul.Score.HasValue ul.Score:? 0)});    

Comments