【发布时间】:2016-12-01 09:52:56
【问题描述】:
在使用整数键时,我在 ASP.NET 中使用 OData V4 服务时遇到问题。我没有使用实体框架,因为我从 SOAP 服务获取数据。
这是我的数据类:
public class RecipeDto
{
public RecipeDto();
public RecipeDto(string name);
public RecipeDto(int ident);
public string Description { get; set; }
public int Ident { get; set; }
public string Name { get; set; }
public List<RecipeVersionDto> Versions { get; set; }
}
我使用 fluent API 设置我的密钥:
var rtdto = builder.EntitySet<RecipeTemplateDto>("AgentConfigTemplates").EntityType
.HasKey(r => r.Ident)
.HasMany(r => r.Versions);
这是我的服务元数据:
<EntityType Name="RecipeTemplateDto">
<Key>
<PropertyRef Name="Ident"/>
</Key>
<Property Name="Ident" Type="Edm.Int32" Nullable="false"/>
<Property Name="Description" Type="Edm.String"/>
<Property Name="Name" Type="Edm.String"/>
<NavigationProperty Name="Versions" Type="Collection(Ifmdatalink.Linerecorder.Backend.PlugIn.dto.RecipeTemplateVersionDto)"/>
</EntityType>
现在我希望通过使用此查询获得我的实体集的第一个条目:
GET http://localhost:13917/my.svc/AgentConfigTemplates(1)
但我总是得到完整的清单。
为什么会发生这种情况,我怎样才能获得第一个条目?
我是否必须以某种方式扩展我的 odata 控制器?
如果我将密钥放在引号中,我会收到错误的请求响应。
【问题讨论】:
标签: asp.net odata .net-4.6.1