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

Ask A Question

Stats

  • Questions 517k
  • Answers 517k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Look at the ntpath module On Linux, I did: >>… May 16, 2026 at 7:53 pm
  • Editorial Team
    Editorial Team added an answer It's not possible to have Riak call back into your… May 16, 2026 at 7:53 pm
  • Editorial Team
    Editorial Team added an answer Resolved The correct path was : ../../demoinclude/ And there was… May 16, 2026 at 7:52 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Current Implementation Sql Server 2005 Database with a table called messages with a column
I have a user defined function in a SQL Server 2005 database which returns
My DAL is created using Linq and all is fine. However, on one page,
I have a problem I am trying to resolve. We have a SQL Server
I have 2 linq 2 SQL statements I'd like to be in a transaction
I'm using C# , .NET and SQL Server with Linq2SQL. What does this error
I am using LINQ To SQL and calling stored procedures to insert the new
I have a strongly typed DataTable created with the VS2005/VS2008 DataSet designer. The table
I need to mirror all of the DNS entries on our DNS server in
I use Linq to SQL in my project. I fetch data from a SQL

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.