Re: LINQ Where 1=0
- From: "Jialiang Ge [MSFT]" <jialge@xxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 30 Jun 2008 17:30:44 +0800
Hello Chunk
I also did not notice the property ¡°StoreOriginalValuesInViewState¡± at the
beginning of the thread. You may want to have a look at the ¡°Remarks¡±
section of LinqDataSource.StoreOriginalValuesInViewState Property in MSDN:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linqdatasource.storeoriginalvaluesinviewstate.aspx
<quote>
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.
</quote>
As well as this walkthrough: Using a Timestamp with the LinqDataSource
Control to Check Data Integrity
http://msdn.microsoft.com/en-us/library/bb470449.aspx
Regards,
Jialiang Ge (jialge@xxxxxxxxxxxxxxxxxxxx, remove 'online.')
Microsoft Online Community Support
=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@xxxxxxxxxxxxxx
This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
"Chuck P" <Chuck@xxxxxxxxxxxxxxxx> wrote in message
news:D283600C-2438-4D0E-A1EF-17276496D35B@xxxxxxxxxxxxxxxx
I got the delete to work by changing the LinqDataSource to storeviewstate
values.
The documentation says I don't have to:
http://msdn.microsoft.com/en-us/library/bb547113.aspx
The docs aren't to clear though:
If you programmatically create the context object in the Selecting event
and
you do not have to store original values in the view state, the
ContextCreating and ContextCreated events are skipped.
I do create a context object, however, I guess it gets assigned during
e.Result=query?
If I turn viewstate off my sql statement becomes:
DELETE FROM [dbo].[UsersInRoles] WHERE ([UsersInRolesID] = @p0) AND
([RowVersion] = @p1)',N'@p0 int,@p1 timestamp',@p0=75,@p1=NULL
Apparently it doesn't know the value of the TimeStamp, since the value of
NULL is passed. I put the RowVersion in the gridview and got the same
result.
.
- References:
- LINQ Where 1=0
- From: Chuck P
- RE: LINQ Where 1=0
- From: "Jialiang Ge [MSFT]"
- LINQ Where 1=0
- Prev by Date: Re: Linq to Sql providers
- Next by Date: Re: Linq to Sql providers
- Previous by thread: RE: LINQ Where 1=0
- Next by thread: "Database" missing in VS C++ 2008 CLR Windows Forms Application
- Index(es):
Relevant Pages
|