Quantcast
Channel: MySQL Forums - Connector/NET and C#, Mono, .Net
Viewing all articles
Browse latest Browse all 1447

MySql.EntityFrameworkCore No DbUpdateConcurrencyException thrown when concurrency conflictis expected (no replies)

$
0
0
当使用 MySql.EntityFrameworkCore 连接mysql 时候,更新数据出现并发的时候 也没有 抛出 DbUpdateConcurrencyException 异常信息
,代码如下

services.AddDbContext<testContext>(

(sp,optionsBuilder) =>
{
optionsBuilder.UseMySQL(connectionString)
.EnableDetailedErrors()
.EnableSensitiveDataLogging();
});


[Table("user_account2")]
public class UserAccount
{
[Column("id")]
public int Id { get; set; }

[Column("user_id")]
public int? UserId { get; set; }


[StringLength(11)]
//[Comment("账号名称")]
[Column("account_name")]
public string AccountName { get; set; }



//[Comment("创建时间")]
[Column("create_time")]
public DateTime? CreateTime { 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: "create_at", TypeName = "timestamp")]
public DateTime? CreateAt { 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.CreateAt= DateTime.UtcNow;
testContext.UserAccounts.Update(userAccount);
int rows= testContext.SaveChanges();
Console.WriteLine(rows);
}
catch (DbUpdateConcurrencyException ex)
{

throw ex;
}
执行结果永远都还返回是1,没有抛出 DbUpdateConcurrencyException 异常

Viewing all articles
Browse latest Browse all 1447

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>