Home > Net >  Share the case: EF] [LINQ usage multi-table linkage embedded subqueries Count grouping usage
Share the case: EF] [LINQ usage multi-table linkage embedded subqueries Count grouping usage

Time:04-24

SQL prototype:
 
The select a. ranjobId
, a. obno
, b.J obna
, Planqty
, Jobqty=(select count (Manno) from BgMan c where a. ranno=mount ranno and a. obno=SAN Antonio obno) - personnel file table
, Overtime=sum (a.O vertime)

The from BranJob a - positions table
Left the join JobSet b on a. obno=b.J obno - position table
Where a. ranno='006'

Group by a. ranjobId, a. ranno, a. obno, b.J obna, Planqty
The order by a. ranjobId


EF joint query usage:
 
///& lt; summary>
///department position information
///& lt;/summary>
///& lt; Param name="branno & gt;" Department number & lt;/param>
///& lt; Returns>
Public static DataTable GetBranjob (string branno)
{
Try
{
Using (CusProContext db=new CusProContext ())
{
Var BranjobObj=(from p in the db. BranJob
Where p.B ranno==branno

Join a db in JobSet on p.J obno equals a. obno into t1
From a in t1. DefaultIfEmpty ()

Join in the db. B BgMan on new {p.B ranno, p.J obno} equals new {b.B ranno, b.J obno} into t2
The from c in t2. DefaultIfEmpty ()

Group c by new
{
P.B ranjobId,
P.J obno,
A. obna,
P.P lanqty,
P.O vertime
} into GRP

Select new
{
GRP. Key. BranjobId,
GRP. Key. Jobno,
GRP. Key. Jobna,
GRP. Key. Planqty,
Jobqty=GRP. The Count (x=& gt; X.M anno!=null),
Lackqty=GRP. Key. Planqty - GRP. The Count (x=& gt; X.M anno!=null),
GRP. Key. Overtime
}). ToList ();

Return LinqToDataTable (BranjobObj);
}
}
The catch (Exception ex)
{
throw ex;
}
}


Here is used in the query of leftist writers usage, if less than don't have any place, welcome to correct me a great god,

CodePudding user response:

Thanks for sharing, although didn't see the problem, but does not affect me Posting praise,

CodePudding user response:

Thank you moderator greatly
  •  Tags:  
  • C#
  • Related