我正在使用MVC 5、Microsoft OData 2.1和Entity Framework 6。我试图使用EntitySetController类编写OData feed,然后消费它。当我添加服务引用并且它消耗OData metadata时,它可以看到我的资源,但是当我尝试保存它时,会出现以下错误:
“DataServicesCoreClientGenerator”自定义工具失败。数据服务客户端代码生成失败:指定的模式无效。错误:(0,0) :错误0159:实体“...”未定义键。为此EntityType定义键。
我的OData Metadata如下所示:
但这并没有改变我的元数据,错误仍然存在。EDMX模型中的实体键设置为ApplicationId。这似乎也不影响元数据。我该如何让元数据生成一个包含实体键的架构,以便我可以通过服务引用在C#中使用它?
附注:我正在使用视图。当我直接使用表时它似乎起作用。那么我该如何让它在视图中起作用?
“DataServicesCoreClientGenerator”自定义工具失败。数据服务客户端代码生成失败:指定的模式无效。错误:(0,0) :错误0159:实体“...”未定义键。为此EntityType定义键。
我的OData Metadata如下所示:
<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" Version="1.0">
<edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="3.0" m:MaxDataServiceVersion="3.0">
<Schema xmlns="http://schemas.microsoft.com/ado/2009/11/edm" Namespace="WcfResearch.Entities">
<EntityType Name="vApplication">
<Property Name="ApplicationName" Type="Edm.String"/>
<Property Name="LoweredApplicationName" Type="Edm.String"/>
<Property Name="ApplicationId" Type="Edm.Guid" Nullable="false"/>
<Property Name="Description" Type="Edm.String"/>
</EntityType>
</Schema>
<Schema xmlns="http://schemas.microsoft.com/ado/2009/11/edm" Namespace="Default">
<EntityContainer Name="Container" m:IsDefaultEntityContainer="true">
<EntitySet Name="Applications" EntityType="WcfResearch.Entities.vApplication"/>
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
我尝试使用以下代码将[Key]属性添加到vApplication类:
[MetadataType(typeof(vApplicationKey))]
public partial class vApplication
{
}
public class vApplicationKey
{
[Key]
public System.Guid ApplicationId { get; set; }
}
但这并没有改变我的元数据,错误仍然存在。EDMX模型中的实体键设置为ApplicationId。这似乎也不影响元数据。我该如何让元数据生成一个包含实体键的架构,以便我可以通过服务引用在C#中使用它?
附注:我正在使用视图。当我直接使用表时它似乎起作用。那么我该如何让它在视图中起作用?