Translate from SQL to Linq -


i'm new whole linq story, have understanding in sql.

i need rebuild query sql linq. sql query working , far have tried myself linq without result...

is possible me translate query sql linq?
i'm ready learn new in whole story. nice if why working in linq.

sql statement

select timereport.entrydate      , sum(timereport.hours) hours      , sum(billingrate.hourlyrate * timereport.hours) amount billingrate      inner join activity          on billingrate.billingrateid = activity.billingrateit          inner join timereport              on activity.activityid = timereport.activityid                  right outer join dossier                      on timereport.dossierid = dossier.dossierid                     inner join lbu                          on dossier.lbuid = lbu.lbuid                      inner join bu                          on dossier.buid = bu.buid   group timereport.entrydate having sum(timereport.hours) > 0 order timereport.entrydate desc 

what have tired linq

var x = (from br in ctx.billingrate                     join in ctx.activity on br.billingrateid equals a.billingrateit                     join tr in ctx.timereport on a.activityid equals tr.activityid                      select br)                   .groupjoin(                      (from d in ctx.dossier                        join l in ctx.lbu on d.lbuid equals l.lbuid                        join b in ctx.bu on d.dossierid equals 

thanks , fast answer.

i appreciated every effort !!

joins aren't necessary when have navigation properties. since don't know model looks like, use following starting point , adjust own specifications:

// starting dossier handles right outer join condition var timerecordquery =          d in ctx.dossier         tr in d.timereports         // handles inner join conditions after right outer join         d.lbuid.hasvalue && d.buid.hasvalue         // project want use         select new          {             entrydate = tr.entrydate,             hours = tr.hours,             // use navigation properties, no need join             amount = tr.activity.billingrate.hourlyrate * tr.hours          };  var resultsquery = e in timerecordquery                    // group entrydate                    group e e.entrydate g                    // sum of hours each entrydate value                    let hours = g.sum( x => x.hours )                     // having clause                    hours > 0                    // project results                    select new                     {                        entrydate = g.key,                        hours = hours,                        amount = g.sum( x => x.amount )                     }; 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

node.js - Bad Request - node js ajax post -

uitableview - Create and use custom prototype table cells in xamarin ios using storyboard -