Experience Summary 16--EF local data update

Source: Internet
Author: User

EF provides the function of updating some data of an object while retaining other data.

1. Re-instance an object and give the ID and fields to be modified. Note: The entity here cannot be queried from the database, but can only be a new instance.

Order order = new Order () {ID = id };
Order. Name = "test222 ";

2. Contains the object. The update policy is "Unchanged" and the fields to be updated are set.

DbEntityEntry <Order> entry = db. Entry <Order> (order );
Entry. State = EntityState. Unchanged;
Entry. Property (o => o. Name). IsModified = true;

3. Submit updates.
Db. SaveChanges ();

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.