This is my existing LINQ SQL. At the moment it works, however the using the coalescing operator for null results on the "let" clauses make me feel like I'm violating some sort of unwritten rule. Is there a better way?
Also, as this is on a web server, I don't know if this should be set static or not. Methinks not. But how do I get around that? It winds up being bound to a GridView.
public static List<TrackingComputer> TrackingBoardPCsgroup(string groupName)
{
using (dbiemrDashboardDataContext db = new dbiemrDashboardDataContext())
{
var query =
(from t in TrackingBoardPCs()
where t.TrackingGroup == groupName
join p in db.GetTable<tblTBHealthPing>() on t.ComputerAsset equals p.ComputerAsset
into pingInfo
join h in db.GetTable<tblTBHealthHeartbeat>() on t.ComputerAsset equals h.ComputerAsset
into heartbeatInfo
let p = pingInfo.OrderByDescending(p => p.HealthPingTime).DefaultIfEmpty().First() ?? new tblTBHealthPing() { ComputerAsset = "Not Found", HealthPingResult = false, HealthPingTime = DateTime.Now}
let h = heartbeatInfo.OrderByDescending(p => p.HealthHeartbeatTime).DefaultIfEmpty().First() ?? new tblTBHealthHeartbeat(){ ComputerAsset = "Not Found", HealthCurrentUser = "Not Found", HealthCurrentWindow = "Not Found", HealthHeartbeatTime = DateTime.Now, HealthUptime = string.Empty}
let tc = new TrackingComputer
{
ComputerName = t.ComputerAsset,
IPAddress = t.ComputerIP,
Location = t.Location,
Pingable = p.HealthPingResult ?? false,
PingTime = p.HealthPingTime ?? DateTime.Now.AddDays(-100),
Username = h.HealthCurrentUser ?? "Not Found",
CurrentWindow = h.HealthCurrentWindow ?? "Not Found",
Uptime = h.HealthUptime ?? "Not Found",
HeartbeatTime = h.HealthHeartbeatTime ?? DateTime.Now.AddDays(-100)
}
orderby tc.Pingable
select tc).ToList<TrackingComputer>();
return query;
}
}
{Binding Username, TargetNullValue = 'Not found'}
– Dan Lyons Apr 28 at 17:49