When using MySql When the EntityFrameworkCore connects to MySQL, it does not throw the DbUpdateConcurrencyException exception when there is concurrency in updating data
The code is as follows
Services AddDbContext<testContext>(
(sp, optionsBuilder)=>
{
OptionsBuilder UseMySQL (connectionString)
. Enabling DetailedErrors ()
. enableSensitiveDataLogging();
});
[Table ("user_count2")]
Public class UserAccount
{
[Column ("id")]
Public int Id {get; set;}
[Column ("user_id")]
Public int? UserId {get; set;}
[StringLength (11)]
//[Comment ("Account Name")]
[Column ("account name")]
Public string AccountName {get; set;}
//[Comment ("Creation Time")]
[Column ("create-time")]
Public DateTime? Create Time {get; set;}
[Column ("is_delete")]
Public int? IsDelete {get; set;}
[Column ("delete-time")]
Public DateTime? DeleteTime {get; set;}
[Column ("version", TypeName="varchar")]
//[Timestamp]
[ConcurrencyCheck]
//[Timestamp]
Public Guid Version {get; set;}
[Column (name: "createat", TypeName="timestamp")]
Public DateTime? Create At {get; set;}
}
UserAccount? UserAccount=testContext UserAccounts Find (100003);
//Console WriteLine (userAccount. CreateAt?. ToString ("yyyy MM dd HH: mm: ss. fff: ffffff"));
Try
{
UserAccount AccountName="atest";
UserAccount Version=Guid NewGuid();
UserAccount Create At=DateTime UtcNow;
TestContext UserAccounts Update (userAccount);
Int rows=testContext SaveChanges ();
Console WriteLine (rows);
}
Catch (DbUpdateConcurrencyException ex)
{
Throw ex;
}
The execution result always returns 1, and no DbUpdateConcurrencyException exception was thrown
The code is as follows
Services AddDbContext<testContext>(
(sp, optionsBuilder)=>
{
OptionsBuilder UseMySQL (connectionString)
. Enabling DetailedErrors ()
. enableSensitiveDataLogging();
});
[Table ("user_count2")]
Public class UserAccount
{
[Column ("id")]
Public int Id {get; set;}
[Column ("user_id")]
Public int? UserId {get; set;}
[StringLength (11)]
//[Comment ("Account Name")]
[Column ("account name")]
Public string AccountName {get; set;}
//[Comment ("Creation Time")]
[Column ("create-time")]
Public DateTime? Create Time {get; set;}
[Column ("is_delete")]
Public int? IsDelete {get; set;}
[Column ("delete-time")]
Public DateTime? DeleteTime {get; set;}
[Column ("version", TypeName="varchar")]
//[Timestamp]
[ConcurrencyCheck]
//[Timestamp]
Public Guid Version {get; set;}
[Column (name: "createat", TypeName="timestamp")]
Public DateTime? Create At {get; set;}
}
UserAccount? UserAccount=testContext UserAccounts Find (100003);
//Console WriteLine (userAccount. CreateAt?. ToString ("yyyy MM dd HH: mm: ss. fff: ffffff"));
Try
{
UserAccount AccountName="atest";
UserAccount Version=Guid NewGuid();
UserAccount Create At=DateTime UtcNow;
TestContext UserAccounts Update (userAccount);
Int rows=testContext SaveChanges ();
Console WriteLine (rows);
}
Catch (DbUpdateConcurrencyException ex)
{
Throw ex;
}
The execution result always returns 1, and no DbUpdateConcurrencyException exception was thrown