Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4599916
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:36:34+00:00 2026-05-21T23:36:34+00:00

I’m fairly new to LINQ, so this might be an easy peasy solution for

  • 0

I’m fairly new to LINQ, so this might be an easy peasy solution for some of you. I’ve been ripping my hair out for quite a while now 🙂

Scenario:
I have a 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 explain the data.

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 have 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 because I get all the results I want and more. I don’t need to know that the reading on module 0A, port 1 had counted to 2 before the latest entry of 3.
Does that make sense? 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 trigger on bool values. One means there’s an alarm present on the machine and zero means all is OK.

I’m sorry for the double post. For whatever reason my temporary account was locked out and I couldn’t comment on my old post. Now I’m registered and should hopefully be able to provide additional information.

@Jon Skeet, Here’s the setup with 2 active ports on Module 0B, Imagine that there had been an alarm active on module 0B port 1, then i would still get the outdated data shown even though the problem had been resolved.

https://i.stack.imgur.com/oX1ZK.jpg

Here’s how it would look at my client side:

https://i.stack.imgur.com/stBXY.jpg

Obviously i would only like to display the latest Data. I hope this clears up the confusion.


I seem to have resolved my own issue but in a nonefficient way.

SQLdbDataContext sqlDB = new SQLdbDataContext();

                    var LatestObjects = (from q in sqlDB.CurrentData_Tabels select q).OrderByDescending(x => x.Time).First();

                    var selectedobjects = from q in sqlDB.CurrentData_Tabels
                                          where q.Time == LatestObjects.Time
                                          select q;


                    dgvLiveData.DataSource = selectedobjects;
                    dgvLiveData.RowHeadersVisible = false;  

By combining 2 queries I got what I wanted. I’m sure this could be resolved using one query but I’m nowhere near being a hardcore programmer that would figure that one out.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T23:36:35+00:00Added an answer on May 21, 2026 at 11:36 pm

    What you have done there is correct. You can write it in one query by making the statement for latestquery as subquery in the code, but it doesnt make any different. When you set the query to LatestQuery in your code, no execution is made to the server. The actual fetching is done when the data in the query is used.

    Example:

      var q = dc.Mytable.Where(e=>e.id > 5);    // q is IQueryable, no fetch to db is executed yet
      q = q.Where(e=> e.name.StartWith("a"));   // q is still IQueryable and no fetch yet too
      var list = q.List();   // Fetching of data to the db happens here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.