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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:30:01+00:00 2026-05-26T05:30:01+00:00

The Linq-To-SQL that needs refactoring is found below: var query = from p in

  • 0

The Linq-To-SQL that needs refactoring is found below:

   var query = from p in Cache.Model.Products
               join sc in Cache.Model.ShishaCombinations on p.ProductID equals sc.ProductID
               where sc.NumberOfMixes ==  mixes
               select new { p.ProductID, p.Name };

with the following one-liner:

   group by p.ProductID

I know that group by omits any need for the select clause so both can live together in the same LINQ-To-SQL statement so can someone help me refactor the above please?

To help me remove any repeating data in my results. <– This is the entire point in this question. A product is repeated a number of times based on the number of Flavours that are used by the product. So as a result in the ‘ShishaCombinations’ table one ProductID may be repeated many times one for each flavour that it uses. I would like to group the results returned from the query above or call distinct on it as I don’t want add the product ‘n’ times to my GUI because it appears ‘n’ number of times in my results. Hopefully that will clear up any confusion of what I am trying to do.

  • 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-26T05:30:02+00:00Added an answer on May 26, 2026 at 5:30 am

    The code below is all what I needed:

            var query1 = (from p in Cache.Model.Products
                         join sc in Cache.Model.ShishaCombinations on p.ProductID equals sc.ProductID
                         where sc.NumberOfMixes == mixes
                         select new { p.ProductID, p.Name }).Distinct();
    

    Ufuk, thanks for answering mate. I knew my answer was a simple one lol : )

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

Sidebar

Related Questions

I have a class that needs a property set inside a LINQ-to-SQL query. My
I'm writing a bit of LINQ to SQL that needs to perform a search
I have a LINQ-to-SQL DataContext that represents a parent-child relationship of Products to Prices.
I have a Linq to SQL query that was working just fine with SQL
I'm trying to run a LINQ to SQL query that returns a result in
I have an application that needs to join tables from multiple databases into a
I am using LINQ-to-SQL for an application that queries a legacy database. I need
I've got some LINQ to SQL that sometimes throws a Cannot insert duplicate key
I have a LINQ TO SQL Context that I have created that calls a
I have a class containing Linq To SQL objects that are used to populate

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.