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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:13:57+00:00 2026-06-03T08:13:57+00:00

I have an Entity Framework Entity that looks something like this: class ListItemEtlObject {

  • 0

I have an Entity Framework Entity that looks something like this:

class ListItemEtlObject
{
    public int ID { get; set; }
    public string ProjectName { get; set; }
    public string ProjectType { get; set; }
    public string ProjectCode { get; set; }
    public string ProjectDescription { get; set; }
    public string JobNo { get; set; }
    public string JobDescription { get; set; }
    public bool Include { get; set; }
}

I am pulling items from two different data sources into IEnumerable lists. How might I go about comparing the items without using a bunch of if statements to check if there are differences between the properties’ values and then set the property’s value if they do not match? The idea is to keep the lists synchronized. Also list A has an ID value set, list B does not. I just feel there is a better way to do this than a bunch of

if(objectA.ProjectName != objectB.ProjectName)
{
   objectA.ProjectName = objectB.ProjectName;
}
  • 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-03T08:13:58+00:00Added an answer on June 3, 2026 at 8:13 am

    If you have control of the source object then the best declarative way to support value based equality is to implement IEquatable<T>. This does unfortunately require you to enumerate out all of those checks but it’s done once at the actual object definition location and doesn’t need to be repeated throughout the code base.

    class ListItemEtlObject : IEquatable<ListITemEtlObject>
    {
      ...
      public void Equals(ListITemEtlObject other) {
        if (other == null) {
          return false;
        }
        return 
          ID == other.ID &&
          ProjectName == other.ProjectName &&
          ProjectType == other.ProjectType &&
          ... ;
      }
    }
    

    Additionally you could choose to overload the equality operator on the object type and allow consumers to simply use != and == on ListItemEtlObject instances and get value equality instead of reference equality.

    public static bool operator==(ListItemEtlObject left, ListItemEtlObject right) {
      return EqualityComparer<ListItemEtlObject>.Default.Equals(left, right);
    }
    public static bool operator!=(ListItemEtlObject left, ListItemEtlObject right) {
      return !(left == right);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object hierarchy that looks something like this: public class Book {
I have an Entity in Code First Entity framework that currently looks like this:
I have a LINQ query mapped with the Entity Framework that looks something like
I have a repository accessing my Entity Framework. I have a method that looks
I'll let the code do the talking here, I have something like this: class
If I had a SQL Server table that looks something like this with some
Let's say I have a Student entity like this implemented using the Play Framework's
I have one project which has RIAService with entity framework that is referenced to
I have an Entity Framework generated table with values in a td that I
In Entity Framework 4.2 I have a Trips entity that can have 0..* PlacesOfInterest

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.