2015-02-23 35 views
1

在复杂类型内部添加关系时出现跟随错误。我该如何解决这个问题。我大吃一惊,认为这是OData V3的问题,而不是OData V4的问题。WebAPI和Odata V4问题:包含实体的ComplexType

复杂类型'Microsoft.OneIM.ActiveIncident.Contracts.IncidentImpact'通过属性'ImpactedServices'引用实体类型'Microsoft.OneIM.ActiveIncident.Contracts.ImpactedService'。

在System.Web.OData.Builder.ODataConventionModelBuilder.MapComplexType(ComplexTypeConfiguration的complexType) 在System.Web.OData.Builder.ODataConventionModelBuilder.MapType(StructuralTypeConfiguration edmType) 在System.Web.OData.Builder.ODataConventionModelBuilder.AddComplexType (类型类型) 在System.Web.OData.Builder.ODataConventionModelBuilder.ReconfigureEntityTypesAsComplexType(EntityTypeConfiguration [] misconfiguredEntityTypes) 在System.Web.OData.Builder.ODataConventionModelBuilder.RediscoverComplexTypes() 在System.Web.OData.Builder.ODataConventionModelBuilder。 GetEdmModel() at c:\ OneIM \ EngSys \ One中的Microsoft.OneIM.ActiveIncident.Service.ModelBuilder.BuildIncidentModels() IM \ ActiveIncident \ src \ Product \ Service \ Models \ ModelBuilder.cs:line 42 at Microsoft.OneIM.ActiveIncident.Service.WebApiConfig.Register(HttpConfiguration config)in c:\ OneIM \ EngSys \ OneIM \ ActiveIncident \ src \ Product \ Service \ App_Start \ WebApiConfig.cs:line 22 at c:\ OneIM \ EngSys \ OneIM \ ActiveIncident \ src \ Product \ ServiceHost \ ApiStartup.cs中的Microsoft.OneIM.ActiveIncident.ServiceHost.ApiStartup.Configuration(IAppBuilder appBuilder)线27

我的模型看起来如下

public class Incident 
    { 
      public IncidentImpact Impact { get; set; } 
    } 

[ComplexType] 
public class IncidentImpact 
{ 

    public bool IsCustomerImpacting { get; set; } 

    public string SupportTicketId { get; set; } 

    public ICollection<ImpactedService> ImpactedServices { get; set; } 
} 


public class ImpactedService 
{ 

    public long Id { get; set; } 


     public long IncidentId { get; set; } 

    public Incident Incident { get; set; } 

    public long ServiceId { get; set; } 
} 

回答

1

尽管OData协议V4支持复杂类型包含实体作为导航属性,但OData Lib和WebAPI OData都不会现在实现此功能。

0

你必须设置由[关键]属性或模型构建器作为

0123的关键特性
builder.EntitySet<Type>("Types").EntityType.HasKey(t => t.KeyProperty); 

希望它有帮助。

+1

这没有奏效,并给了相同的错误 – sammym 2015-02-24 20:19:54