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

  • Home
  • SEARCH
  • 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 8244579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:54:04+00:00 2026-06-07T21:54:04+00:00

I am updating a database table using EF. Its a simple scenario in connected

  • 0

I am updating a database table using EF.

Its a simple scenario in connected mode.

I get the row I want to update

var order = from o in Orders
        where o.ID = 1
        select o;

I then update the record as:

order.FirstName = "First";
order.LastName = "Last";
context.SaveChanges();

It works fine. EF checks if the field has changed and only updates the field if its a new value. I have enabled CDC on my SQL server to check that EF does not rewrite to the database if the value has not changed.

Now I want to put this check in my code for additional logic i.e. I want EF to tell me when the record was updated, and when it was not (because the value has not changed).
Can anyone please tell if there is a way?

I do not want to manually check each field as I have a lot of fields to compare.

Thanks

  • 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-07T21:54:07+00:00Added an answer on June 7, 2026 at 9:54 pm

    If anybody is interested, here is what I did. I created the following method to check if any field has changed before saving changes.

    private Dictionary<Type, bool> IsEntityModified()
    {
        Dictionary<Type, bool> entity = new Dictionary<Type, bool>();
        var items = _bentities.ObjectStateManager.GetObjectStateEntries(EntityState.Modified);
        foreach (ObjectStateEntry entry in items)
        {
            foreach (string propName in entry.GetModifiedProperties())
            {
                string oldsetterValue, newsetterValue = null;
                // Get orginal value 
                oldsetterValue = entry.OriginalValues[propName].ToString();
                // Get new value 
                newsetterValue = entry.CurrentValues[propName].ToString();
    
                if (oldsetterValue != newsetterValue)
                {
                    entity.Add(entry.Entity.GetType(), true);
                }
            }
        }
        return entity;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table which I want to update using a simple update command.
Trying to simple update a row in an SQLiteDatabase Database. I can insert records
I am updating table using PreparedStatement the following code works perfectly pst = conn.prepareStatement(UPDATE
I want to update data from my database using java. I have established my
I need to take some actions which involve updating a database table when a
I'm updating a program and adding a new table to the database. The program
I am having trouble UPDATING my database using FMDB . Here's my SQL BOOL
At my company, our current method of updating the database is to connect using
I am having trouble updating my Database from my code using a DataSet. I'm
I'm attempting to update a row using: myDatabase.update(DATABASE_TABLE, cvUpdate, KEY_NAME + = + mName,

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.