【发布时间】:2015-10-15 06:11:03
【问题描述】:
我正在尝试使用补丁更新 OData 中的记录,但该表由多个主键组成,因此它给出了错误 “传递的主键值的数量必须与实体上定义的主键值的数量相匹配。ASP.NET MVC 实体框架”
这里是示例代码。
public async Task<IHttpActionResult> Patch(Delta<PreferenceFormat> patch)
{
Validate(patch.GetEntity());
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
PreferenceFormat PreferenceFormat = await db.PreferenceFormats.FindAsync(_userId);
if (PreferenceFormat == null)
{
return NotFound();
}
patch.Patch(PreferenceFormat);
try
{
await db.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!PreferenceFormatExists(_userId))
{
return NotFound();
}
else
{
throw;
}
}
return Updated(PreferenceFormat);
}
这里需要传递4个主键参数:
PreferenceFormat PreferenceFormat = await PreferenceFormats.FindAsync(_userId);
我怎样才能达到同样的效果。
【问题讨论】:
标签: asp.net-mvc asp.net-web-api odata patch delta