我有在数据库中创建新电子邮件的操作。代码就像:
[ValidateModel]
public HttpResponseMessage Post(string username, [FromBody] EmailDTO email)
...
this.repository.Add(username, email)
Run Code Online (Sandbox Code Playgroud)
但是API用户可以设置'Id'属性,这会导致数据库冲突。绑定时无需创建自定义模型绑定程序或更改DTO的构造函数,我是否可以忽略“ Id”属性?像Bind(Exclude ='...'),但是在WebApi中?
有什么已知的方法可以防止在控制器动作中进行大规模分配?