tsql - LINQ To SQL Grouping -


Do some kind of spirit please lend Linq to SQL query for the following T-SQL queries

  e.EmployeeName, Min (a.SignInTime), Max (a.SignOutTime) selects e.Id = a.EmployeeId on employee E Left External and Artists Presence a JOIN (CONVERT (varchar, a.SignInTime, 106 ) AS DATETIME) = '28 April 2009 'Group by E. Employee Employee Name  

I have a database schema as follows

  Employee: {ID: Int identity P, EmployeeName: varchar (200) No NULL} Attendance: {Number: Integer Identity P, EmployeeID: int FK (Employee) No NULL, SignInTime: DATETIME, SignOutTime: DATETIME}  

Note: Convert The use of the dimic is only used to cut parts of time into signtime for comparison

Choose one Nuti is it ugly, but it does the trick, it gives exactly what you are looking for. In the case of employees without presence, you get back the name in a futile time.

  var selectedDate = new date time (200 9, 28); Var query = e join db.Employees DB. Present at the E.Id with temp.DefaultIfEmpty () in temp with a.EmployeeId.T.SignInTime == faucet || (T.SignInTime & gt; = selectedDate & amp; amp; t.SignInTime & LT; selectedDate.AddDays (1)) Categorized Selected {employee = grouped.Key, FirstSignInTime = grouped.Min (in a = & gt; Group t; A.SignInTime by e.EmployeeName, LastSignOutTime = Grouped. Max (a => a.SignOutTime)};  

This is a SQL that is emitted from the expression:

  DECLARE @ p0 Date time = '2009-04- 27 00: 00: 00.000 'Declaration @ p1 Date Time =' 2009-04-28 00: 00: 00.000 'as selected ([FirstSignInTime], Max (.t1] as Min (. [T1] [SignInTime] [LastSignOutTime], [t0] as [SignOutTime]). As [EmployeeName] [employee] as [employee] [t0] on the [t0] as the [external] join [t0] in the form of [external] external. [Id] = [t1]. [EmployeeID] Where ([t1] [SignInTime] is zero.) Or ([[t1] [SignInTime]> gt; .. = @ p0) and [[t1] [SignInTime] & lt; @ p1) [ T0] Group [EmployeeName. ]  

It is very close to your original SQL I said that "T. signtime == blank" so that he returns the staff back with presence, but you can remove it If that's not what you want.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -