LINQ to SQL Tutorial
Lesson 19 of 38 · Part 19 UpdateCheck property · Database
Part 19 UpdateCheck property
Text version of the video
http://csharp-video-tutorials.blogspot.com/2014/10/part-19-updatecheck-property.html
Slides
http://csharp-video-tutorials.blogspot.com/2014/10/part-19-updatecheck-property_7.html
LINQ to SQL Tutorial – All Text Articles & Slides
http://csharp-video-tutorials.blogspot.com/2014/09/linq-to-sql-tutorial.html
LINQ to SQL Tutorial Playlist
Dot Net, SQL, Angular, JavaScript, jQuery and Bootstrap complete courses
https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd
This is continuation to Part 18. Please watch Part 18, before proceeding. UpdateCheck property of ColumnAttribute class is used to determine how LINQ to SQL detects concurrency conflicts.
This property can be set to one of the 3 values of the UpdateCheck enum. This enum is present in System.Data.Linq.Mapping namespace. The following are the different values of UpdateCheck enum and what they mean.
Always – Always use this column for conflict detection.
Never – Never use this column for conflict detection.
WhenChanged – Use this column only when the member has been changed by the application.
The default is Always. This means by default all the columns will be used to detect concurrency conflicts.
Example :
1. Open Sample.dbml file and right click on “AccountBalance” property and select “Properties” option from the context menu.
2. In the properties window set, UpdateCheck = Never. At this point open, Sample.Designer.cs file and notice that the AccountBalance property has UpdateCheck property applied.
[global::System.Data.Linq.Mapping.ColumnAttribute
(Storage=”_AccountBalance”, DbType=”Int”, UpdateCheck=UpdateCheck.Never)]
public System.Nullable[int] AccountBalance
{
get
{
return this._AccountBalance;
}
set
{
if ((this._AccountBalance != value))
{
this.OnAccountBalanceChanging(value);
this.SendPropertyChanging();
this._AccountBalance = value;
this.SendPropertyChanged(“AccountBalance”);
this.OnAccountBalanceChanged();
}
}
}
3. Open SQL Profiler and run a new trace
4. Run the application and click “Deposit $500” button
5. Inspect the generate UPDATE SQL command.
exec sp_executesql N’UPDATE [dbo].[Accounts]
SET [AccountBalance] = @p2
WHERE ([AccountNumber] = @p0) AND ([AccountName] = @p1)’,
N’@p0 int,@p1 nvarchar(4000),@p2 int’,@p0=1,@p1=N’John Mary’,@p2=2200
Notice, that AccountBalance is removed from the WHERE clause, which means this column is not used for detecting concurrency conflicts.