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

后端 未结 1 636
时光取名叫无心
时光取名叫无心 2021-01-06 03:04

I\'m getting started with OData and Entity Framework.

I created a Controller that exposes Customer. In the model (edmx) there\'s only one Entity (Customer) and ever

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-06 04:02

    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("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'.

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

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

    0 讨论(0)
提交回复
热议问题