WebAPI和Odata V4问题:包含实体的ComplexType

时间:2015-02-23 18:52:15

标签: asp.net-web-api odata

我在复杂类型中添加关系时遇到以下错误。我该如何解决这个问题。我感到愤怒并且读到它与OData V3有关但在OData V4中没有。

复杂类型' Microsoft.OneIM.ActiveIncident.Contracts.IncidentImpact'指实体类型' Microsoft.OneIM.ActiveIncident.Contracts.ImpactedService'通过物业' ImpactedServices'。

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

我的模型如下所示

    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; }
}

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

您必须按[key]属性设置键属性,或者在模型构建器中设置为

builder.EntitySet<Type>("Types").EntityType.HasKey(t => t.KeyProperty);

希望它有所帮助。