【发布时间】:2017-08-18 22:56:38
【问题描述】:
我创建了一个 azure 移动服务,它基本上由 2 个实体和 2 个 TableControllers 组成。这两个实体具有 1:1 的关系。
public class Entity1 : EntityData
{
public int Value { get; set; }
public DateTime Date { get; set; }
public string Name { get; set; }
public virtual Entity2 Reference { get; set; }
}
public class Entity2 : EntityData
{
public string Name { get; set; }
}
控制器是标准的脚手架生成的控制器。当我尝试插入一个引用已经存在的 entity2 的 entity1 实例时,我收到以下消息:
{"$id":"1","message":"The operation failed due to a conflict: 'Violation of
PRIMARY KEY constraint 'PK_Service.Entity2'. Cannot insert
duplicate key in object 'Service.Entity2'. The duplicate key
value is (32aec44a282e42b7bc51096052335dad).\r\nThe statement has been
terminated.'."}
我在请求正文中使用了以下 JSON:
{
"value": 1,
"date": "2015-04-27T06:51:47.641Z",
"name": "name",
"project": {
"id": "32aec44a282e42b7bc51096052335dad",
}
}
是否可以在 .NET Code First/Azure 移动服务中使用现有实体作为参考?我不太确定这是否是更多与 EF CodeFirst 或 azure 移动服务相关的问题。
谢谢。
【问题讨论】:
标签: c# entity-framework azure ef-code-first azure-mobile-services