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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:09:58+00:00 2026-05-23T13:09:58+00:00

Help with the linq query to select the object where each date only has

  • 0

Help with the linq query to select the object where each date only has item of one value.
So in the following list:

1) 2011-1-4 would be selected because its items are both 25

2) 2011-1-1 would not be selected because it has items 22 and 25

3) 2011-1-2 and 2011-1-3 would be selected because they only have one item.

    public class MyClass
    {
        public DateTime date { get; set; }
        public int item { get; set; }
    }
    static void Main(string[] args)
    {
        List<MyClass> classes = new List<MyClass> 
        {
        { new MyClass() { date = new DateTime(2011, 1, 1), item = 22 } },
        { new MyClass() { date = new DateTime(2011, 1, 1), item = 25 } },
        { new MyClass() { date = new DateTime(2011, 1, 2), item = 23 } },
        { new MyClass() { date = new DateTime(2011, 1, 3), item = 24 } },
        { new MyClass() { date = new DateTime(2011, 1, 4), item = 25 } },
        { new MyClass() { date = new DateTime(2011, 1, 4), item = 25 } },
        };
    }

What about this? Pretty much got from looking at your guys’ answers.

            var results = classes.GroupBy(m => m.date);
        var q = from n in results where n.All( r => r.item == n.First().item) select n;
  • 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-23T13:09:58+00:00Added an answer on May 23, 2026 at 1:09 pm

    This is some unedited ugliness that I’ve run through Linqpad that seems to meet your requirement.

    var query = classes.GroupBy(c => c.date)
                       .Select(g => g.GroupBy(c => c.item))
                       .Where(sg => sg.Count() == 1)
                       .SelectMany(sg => sg)
                       .SelectMany(g => g)
                       .Select(c => c.date)
                       .Distinct();
    

    Returns the dates 1/2, 1/3, and 1/4 as per your requirement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help making a linq query that will select a list of
Can any one help me convert the below code to LINQ? Select Catg,Count(*) From
Please help the SQL Query in LINQ form - C# .NET 3.5 select distinct
I'm stuggling to replicate a SQL query into LINQ. Can any one help? SQL:
I need some help with a LINQ query in VB.Net, please. I have this
I need help with a specific LINQ query (I still suck at em'!) Background
can anyone help me write a linq query, its a bit confusing... Basically i
I need some help adding conditions to a linq query. Take this small example
Can anyone help? I have a linq query which is embedded inside a extension
can anyone help?, i am stuck with a linq query.. basically i have 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.