asp.net core ef 如何防止重复(add)提交?
看了下ef的用法。似乎针对update/edit。可以用
[ConcurrencyCheck] 或者 RowVersion 来防止并发提交修改的问题。。
但是针对数据的ADD方法呢?如何用优雅的方法防止重复的提交?
比如用户有个post表
代码中用User.Post.Add(new Post{"xxxxx"})
用户通过用postman等方法重复提交如何处理?用lock(obj)?
假设模型大概如下:
public class User
{
[ConcurrencyCheck]
public string UserName { get; set; }
public List<Post> Post { get; set; } = new List<Post>();
}
public class Post
{
public string data { get; set; }
}