I am new to entity framework.Can any one explain why we use Concurrency Check attribute in entity framework with example.In scenario we use this attribute.
Thanks in advance..
It's a way to handle conflicts to database changes when multiple users are updating entities at the same time. Adding the ConcurrencyCheck
attribute means that you are telling
Entity Framework to use that property for detecting concurrency conflicts. Entity Framework includes the property in UPDATE
s or DELETE
s to the database.
For database tables that have many columns this can mean very large WHERE
clauses, which can affect performance and require you to manage large amounts of state. For larger databases a row version strategy is preferred.
[Table("Accounts"]
public class Account
{
public Account() {}
[Key]
public int AccountID { get; set; }
[ConcurrencyCheck]
public string AccountName { get; set; }
}
SQL Server will include AccountName
in UPDATE
s or DELETE
s to the database:
exec sp_executesql N'UPDATE [dbo].[Accounts]
SET [AccountName] = @0
WHERE (([AccountId] = @1) AND ([AccountName] = @2))
',N'@0 nvarchar(max) ,@1 int,@2 nvarchar(max) ',@0=N'Dick',@1=1,@2=N'Harry'
go
This returns no (zero) rows to the user because of the concurrency check.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With