I'm fairly new to LINQ, so this might be an easy peasy for some of you, but I've been ripping my hair out for quite a while now :)
Scenario : I have box containing 3 Hardware Modules that have diffrent ports. Using Serial comunication i 开发者_运维问答extract data from the modules into a SQL table called CurrentData_Tables So each time a unit gets produced, my program will write an entry into the table saying how big the sum is. Let me try and visualize it.
BoxID, ModuleID, PortNumber, Value, Time
1, 0A, 1, {Value}, {Date}
The time is excatly the same on the readings for that specific module, so i imagined i could group by the data that is constant and then just get the latest. This is what i got up with so far :
SQLdbDataContext sqlDB = new SQLdbDataContext();
BindingSource bs = new BindingSource();
var Latest = from q in sqlDB.CurrentData_Tabels
group q by new
{
q.BoxID,
q.ModuleID,
q.PortNumber,
q.Time
}
into groupOrder
select new
{
BoxID = groupOrder.Key.BoxID,
ModuleID = groupOrder.Key.ModuleID,
Portnumber = groupOrder.Key.PortNumber,
Time = groupOrder.Key.Time
};
And that's perfectly fine, i get all the results i want... And more, i dont need to know that the reading on module 0A, port 1 had counted to 2 before the latest entry of 3.. Is this understandable ? , If not please let me try to explain it again :)
Doing a > to get the largest sum wouldn't work, since i also have statuses that triggers on bool values, 1 means there's an alarm present on the machine, and 0 means all is OK!
I think you need to remove the Time field from the group expression and use a Max in the Select new.
精彩评论