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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:04:05+00:00 2026-06-10T07:04:05+00:00

mysql fields look like: Entity Framework with mysql on existting database my application is

  • 0

mysql fields look like:

Entity Framework with mysql on existting database

my application is a mvc 4 project using EF 4.4 on mysql with a existting database.

how can i just update a part of then fields when table ‘s all fields are not nullable but have default value .
when create or update persistent to database for a part of field, EF will Automatically fill a null to those do not explicitly specified fields and i will get a exception.

i don’t want modify database. what can i go with this? thank you

Edit:

my code like this… how make changes to it in your opinion?

[HttpPost]
    public ActionResult Edit(Post_15 post)
    {
        if (ModelState.IsValid)
        {

            db.Entry(post).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        return View(post);
    }
  • 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-10T07:04:07+00:00Added an answer on June 10, 2026 at 7:04 am

    You must provide default values to your object (for example in constructor). EF doesn’t play nicely with database default values. With default update EF always sends explicit value for each column. When you send explicit value, the default value the database is not used. If you don’t set the value for property in the application, .NET default value is send to database.

    Alternatively you must handle update in completely different way. You must explicitly set columns you are going to update to ensure that EF will not update other columns.

    var entity = new YourEntity {
        Id = 123,
        ColumnToUpdate = "ABC"
    };
    
    objectContext.Attach(entity);
    ObjectStateEntry entry = objectContext.ObjectStateManager.GetObjectStateEntry(entity);
    entry.SetModifiedProperty("ColumnToUpdate");
    objectContext.SaveChanges();
    

    This code will update only ColumnToUpdate even if there are 20 other persisted properties.

    Edit:

    DbContext alternative:

    var entity = new YourEntity {
        Id = 123,
        ColumnToUpdate = "ABC"
    };
    
    dbContext.Entities.Attach(entity);
    DbStateEntry<Entity> entry = dbContext.Entry(entity);
    entry.Property(e => e.ColumnToUpdate).IsModified = true;
    dbContext.SaveChanges();
    

    Side note: Only .NET 4.5 supports setting IsModified back to false.

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

Sidebar

Related Questions

I have fields in mysql that look like this: constant1 , constant2, variable1, variable2,
Given 2 fields of type datetime in mySql which look like: 2009-07-26 18:42:21 .
I have a MySQL table called Users. The rows have 4 fields and look
Say I've got a mySQL database table with 4 fields: link_id (primary key) page_id
So, I am modeling a database using MySQL Workbench. I have a table called
I have a table in a mysql-database with the fields name, title, cd_id, tracks
I have a Django project powered by a MySQL database. I fed the database
I'm working with an application that has a MySQL database at Amazon RDS. The
Is it better to use default null or default for text fields in MySQL?
MySQL allows the value of 0000-00-00 for date fields, however ActiveRecord treats an assignment

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.