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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:56:42+00:00 2026-05-15T22:56:42+00:00

I am using LINQ to SQL (SQL Server) with C#. I have a table

  • 0

I am using LINQ to SQL (SQL Server) with C#.

I have a table called “Cars” which automatically becomes the LINQ class/object called “Car”.
All well and good.

Each car has a number of fields, say CarID(primary key int), EngineID, ColourID.

I have 10 existing rows in the Cars table.

Using all the cool LINQ stuff, I create a new “Car” object in C# with an overloaded constructor that I’ve created in my “Car” partial class. So for example:

Car MyCar = new Car(17, 5);

Now this nicely gives me a reference to a new Car object, which I of course haven’t yet committed to the database.

What is the most LINQ-savvy/latest way to run a quick check to ensure that no other cars with the same EngineID and ColourID values exist (I don’t care if they have a different CarID – I just want to compare the other value columns and ensure that I don’t create and insert any more cars with the same Engine/Colour combination).

Is there a cool way to achieve this really quickly with something like:

return db.Cars.Equals(x => MyCar);
  • 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-15T22:56:42+00:00Added an answer on May 15, 2026 at 10:56 pm

    You can use .Distinct with an IEqualityComparer

    var distinctcars = from Repo.cars.Distinct(new MyComparer());
    

    A good example of an IEqualityComparer is here – http://msdn.microsoft.com/en-us/library/bb338049.aspx

    If you check out the ProductComparer example, all you’d probably need to do is replace the “Check whether the products’ properties are equal” part with the check you want to make and that’s pretty much it.

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

Sidebar

Related Questions

I have an application using LINQ-to-SQL with SQL Server CE 4. I know that
I have recursive stored procedure on SQL Server. I'm using Linq-to-SQL generated classes, and
I am implementing geo-location table using SQL Server. I have added major country, states
I am using LINQ to SQL with Sql Server Compact Edition 3.5 and VS2008.
We are using Linq-to-SQL with SQL Server as an ORM on our new project.
I am using the following pattern to update my SQL Server records using Linq
The goal is to issue the fewest queries to SQL Server using LINQ to
How can I retrieve data from a SQL Server using LINQ and display each
I'm using a SQL Server database in my program with Linq-to-SQL I'm using this
How to select all columns from tables in join using linq Sql: select CTRL_RUN_JOB.*,

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.