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 8987575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:49:45+00:00 2026-06-15T21:49:45+00:00

I have a routine where I am accessing a table in the database and

  • 0

I have a routine where I am accessing a table in the database and creating a model from the data.

Database Table TblUNote

      ID      Quarter      Year      SubID      Data
       1          1        2007       245      DataPoint1
       2          1        2007       245      Datapoint2
       3          1        2007       245      Datapoint3
       4          1        2007       247      DataPoint1
       5          1        2007       247      Datapoint2
       6          1        2007       247      Datapoint3
       7          1        2007       249      DataPoint1
       8          1        2007       249      Datapoint2

The routine is

       public RData[] GetData(int Q, int Y)
       {
          using (Entities be = new Entities())
          {
             List<RData> nlist = new List<RData>();

             List<TblUNote> info = be.TblUNotes.Where(a => a.Quarter == Q && a.Year == Y).ToList();
             foreach (var item in info)
             {
                 Rdata newmodel = new RData()
                 {
                    //create model
                 };
             }
             nlist.Add(newmodel);
          }
          return(nlist).ToArray();
       }

This works, but now I need to modify it so that only one model entry is created for each SubID. I have tried using .Distinct() but I just get the same data. I tried to use .First() but I keep getting an error no matter where I put it in the database call. I need the model list to have

               RData Model

     Item1    Quarter = 1,   Year = 2007,  SubID = 245,   Data = DataPoint1
     Item2    Quarter = 1,   Year = 2007,  SubID = 247,   Data = DataPoint1
     Item3    Quarter = 1,   Year = 2007,  SubID = 249,   Data = DataPoint1

The problem is I have nothing to compare SubID to. I thought .Distinct() would have given me a way to do this. I am sure that .First should but how do I integrate it into the database call.

  • 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-06-15T21:49:47+00:00Added an answer on June 15, 2026 at 9:49 pm

    You can use a GroupBy, and take first item of each group :

    be.TblUNotes
      .Where(a => a.Quarter == Q && a.Year == Y)
      .GroupBy(m => m.SubId)
      .Select(g => g.FirstOrDefault())//or g.OrderBy(m => m.Data).FirstOrDefault(), for example, I don't know which item you wanna take
      .ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a routine that will be creating individual tables (Sql Server 2008) to
I have a routine that returns mostly correct data. I pass it a string
I have this routine that works well, but it messes up as it counts
I have a routine which is updating my business entity. The update involves about
I have a routine that examines thousands of records looking for discrepancies. This can
I have a routine that dynamically changes a select list's selected option when the
I have a routine which uses a recursive loop to insert items into a
I'm developing an MVC application and I have a routine that gets the currently
Seems like i need some help with a project. I have a routine ,
I have a jquery routine that calls an MVC action which will do a

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.