I have started writing a query in Linq that looks like this:
var t = (from employee in _session.Query<Employee>()
join logon in _session.Query<WinLogon>() on employee.logon equals logon
join states in _session.Query<AppState>() on logon equals states.logon
join leader in _session.Query<Employee>() on employee.leader equals leader
group new
{
employee, states, logon, leader
}
by new
{
employee_id=employee.id,
employee.first_name, employee.last_name,
leader_1 = leader.first_name,
leader_2 = leader.last_name,
}
into grouped
select new WorkerSummary
{
FullName = grouped.Key.first_name+" "+grouped.Key.last_name,
LeaderFullName = grouped.Key.leader_1+" "+grouped.Key.leader_2,
LogonTime = grouped.Min(a=>a.states.probe_time).ToString(),
WorkstationName = (from events in _session.Query<Event>()
where events.event_type.id == 1
select new { events.event_stamp }).FirstOrDefault().event_stamp.ToString(),
WorkDuration = ""+(grouped.Max(a => a.states.probe_time) - grouped.Min(a=>a.states.probe_time)),
ManualStatus = "" + grouped.Count()
}
).ToList<WorkerSummary>();
But I notice that left join
and subselects like WorkstationName = (from events...
doesn't work with NH Linq. Because in this query will be more subselects, I decide to switch Criteria or HQL.
Am I do something wrong, as I write subselects and such big query? Is there any well known practices to write queries in Linq?
I have started writing a query in Linq that looks like this:
var t = (from employee in _session.Query<Employee>()
join logon in _session.Query<WinLogon>() on employee.logon equals logon
join states in _session.Query<AppState>() on logon equals states.logon
join leader in _session.Query<Employee>() on employee.leader equals leader
group new
{
employee, states, logon, leader
}
by new
{
employee_id=employee.id,
employee.first_name, employee.last_name,
leader_1 = leader.first_name,
leader_2 = leader.last_name,
}
into grouped
select new WorkerSummary
{
FullName = grouped.Key.first_name+" "+grouped.Key.last_name,
LeaderFullName = grouped.Key.leader_1+" "+grouped.Key.leader_2,
LogonTime = grouped.Min(a=>a.states.probe_time).ToString(),
WorkstationName = (from events in _session.Query<Event>()
where events.event_type.id == 1
select new { events.event_stamp }).FirstOrDefault().event_stamp.ToString(),
WorkDuration = ""+(grouped.Max(a => a.states.probe_time) - grouped.Min(a=>a.states.probe_time)),
ManualStatus = "" + grouped.Count()
}
).ToList<WorkerSummary>();
But I notice that left join
and subselects like WorkstationName = (from events...
doesn't work with NH Linq. Because in this query will be more subselects, I decide to switch Criteria or HQL.
Am I do something wrong, as I write subselects and such big query? Is there any well known practices to write queries in Linq?
0 commentaires:
Enregistrer un commentaire