OData的异常复杂类型'WebTools.Order'指的是实体类型“WebTools.Customer”通过属性“客户” [英] OData exception The complex type 'WebTools.Order' refers to the entity type 'WebTools.Customer' through the property 'Customer'

查看:294
本文介绍了OData的异常复杂类型'WebTools.Order'指的是实体类型“WebTools.Customer”通过属性“客户”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用的OData和Entity Framework。

I'm getting started with OData and Entity Framework.

我创建的公开客户的控制器。在模型(EDMX),只有一个实体(客户),一切工作正常(数据正在呈现)。

I created a Controller that exposes Customer. In the model (edmx) there's only one Entity (Customer) and everything works fine (data is being rendered).

现在,当我的许多添加第二个实体(订单)(从数据库更新模型,选择订单),1(1至客户订单多)自动获得的设置。

Now, when I add a second entity (Order) (Update model from database, select Order), the 1 to many (1 Customer to Many Order) gets setup automatically.

我什么也不做,当我编译/运行控制器,我得到这个错误:

I do nothing else and when I compile/run the controller, I get this error:

Line 23:         builder.EntitySet(Of Customer)("Customers")
Line 24:         Return builder.GetEdmModel()  --> Exception Here
Line 25: 
Line 26:     End Function

复杂类型WebTools.Order指的是通过属性客户。

The complex type 'WebTools.Order' refers to the entity type 'WebTools.Customer' through the property 'Customer'.

如果我删除订单实体,它的工作原理。

If I remove the Order Entity, it works.

我不知道问题是否与方程或实体框架的OData的/部分的WebAPI的配置。

I'm not sure if the problem is with the "configuration" of the OData/WebAPI part of the equation or the "Entity Framework".

推荐答案

我假设模型构建器无法弄清楚实体类型订购键属性。你可以帮忙模型构建器通过一对夫妇的方式,

I assume the model builder is not able to figure out the key property for the entity type Order. You can help out the model builder through a couple of ways,


  1. builder.EntitySet<排序>(订单); 。这增加了一个新的EntitySet的'订单',也有纪念型秩序作为一个实体型的效果。您也可以指定订单的关键属性。

  1. builder.EntitySet<Order>("orders");. This adds a new entityset 'orders' and also has the effect of marking the type 'Order' as an entity type. You also have to specify the key property of 'Order'.

标记使用 [重点] 属性类型订单的关键属性(或属性)。

Mark the key property(or properties) on the type 'Order' with the [Key] attribute.

如果你恨属性和preFER在code这样做,你可以做, builder.EntitySet&LT;排序&gt;(订单)EntityType.HasKey(邻。 = GT; order.KeyProperty);

If you hate attributes and prefer doing it in code, you can do, builder.EntitySet<Order>("orders").EntityType.HasKey(o => order.KeyProperty);

这篇关于OData的异常复杂类型'WebTools.Order'指的是实体类型“WebTools.Customer”通过属性“客户”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆