Επεξεργασία

Κοινή χρήση μέσω


LinqDataSource.StoreOriginalValuesInViewState Property

Definition

Gets or sets a value that indicates whether the data from the data source should be stored in view state to make sure that the data has not been changed by another process before it is updated or deleted.

public:
 property bool StoreOriginalValuesInViewState { bool get(); void set(bool value); };
public bool StoreOriginalValuesInViewState { get; set; }
member this.StoreOriginalValuesInViewState : bool with get, set
Public Property StoreOriginalValuesInViewState As Boolean

Property Value

true if the values will be stored in view state; otherwise, false. The default value is true.

Remarks

By default, when update and delete operations have been enabled, the LinqDataSource control stores the original values for all the records in view state. The LinqDataSource control stores values for all primary keys and all properties not marked with UpdateCheck.Never in the Column attribute. You set the UpdateCheck property of the Column attribute in the O/R Designer.

Before LINQ to SQL updates or deletes data, it checks the values in view state against the current values in the data source. If the values do not match, the data source record has changed. In that case, LINQ to SQL throws an exception and does not continue with the update or delete operation. For more information about LINQ to SQL, see LINQ to SQL.

Storing the original values in view state can cause the page size to become unnecessarily large and can expose sensitive data to a malicious user. You can disable storing values in view state by setting the StoreOriginalValuesInViewState property to false. If you do this, you must provide your own way to make sure that the data has not changed. If you set the StoreOriginalValuesInViewState property to false, the original values are not persisted in view state for the data-bound control. In that case, LINQ to SQL cannot verify the integrity of the data. LINQ to SQL will throw an exception that indicates a data conflict even if the data in the data source has not actually changed.

If the underlying data source contains a timestamp field that is automatically updated during an update, you can store only that value in view state. In that case, the timestamp property in the entity class is set to IsVersion=true and all the properties are set to UpdateCheck.Never. Because a timestamp field is automatically updated by the database every time that data in that record changes, LINQ to SQL determines from that value if data has changed. This helps reduce the size of view state, and no sensitive data is exposed. LINQ to SQL will check for data consistency by comparing the timestamp value in view state with the timestamp value in the database. For more information, see Walkthrough: Using a Timestamp with the LinqDataSource Control to Check Data Integrity.

Applies to

See also