다음을 통해 공유


Updating Data (EntityDataSource)

You can use the EntityDataSource control to submit updates to the data source from data-bound Web server controls such as the GridView, DetailsView, or FormView controls. The EntityDataSource control uses an instance of the ObjectContext class to submit the updated values to the database.

Considerations for Updating Data

The following considerations apply when you use the EntityDataSource control to submit updates, inserts, and deletes to the data source:

  • To update data, at least one of the EnableInserts(), EnableUpdates(), or EnableDeletes() properties must be set to true.

  • When you update the data source by using the EntityDataSource control, you can only submit updates for one object at a time.

  • When updates are enabled, you cannot use the CommandText, Select, and GroupBy properties of the EntityDataSource control.

  • You can submit updates to the data source from outside a data-bound control by adding, modifying, and deleting objects in an ObjectContext. For more information, see How to: Add, Modify, and Delete Objects (Entity Framework). After you call the SaveChanges method to commit the changes in the ObjectContext to the data source, call the DataBind method on the data-bound control to update the control with the latest data from the data source.

Storing Object Data in the View State

To track changes when update operations are enabled, the EntityDataSource control must store information about the original values of the properties of loaded objects in the view state for the page. By preserving the original values of object properties across HTTP requests, Object Services manages concurrency by comparing the original values and the current values. For more information about how Object Services manages concurrency, see Change Tracking and Identity Resolution (Entity Framework).

Storing this required information in the view state will increase the page size. You can disable storing values in the view state by setting the StoreOriginalValuesInViewState property to false. If you do this, Object Services cannot track concurrency in updated objects, and you must implement your own concurrency checks. These checks must ensure that the updates that were made in the data-bound control do not conflict with changes that were made in the data source. For more information, see Saving Changes and Managing Concurrency (Entity Framework).

See Also

Concepts

Configuring the EntityDataSource Control

EntityDataSource Designer

Object Context Life-Cycle Management (EntityDataSource)

Other Resources

Working with Objects (Entity Framework)

Change History

Date

History

Reason

July 2008

Added topic.

SP1 feature change.