【问题标题】:WebAPI AND Odata V4 issue: ComplexType containing EntitiesWebAPI AND Odata V4 问题:ComplexType 包含实体
【发布时间】:2015-02-28 09:51:06
【问题描述】:

在复杂类型中添加关系时出现以下错误。我该如何解决这个问题。我大吃一惊,读到它是 OData V3 的问题,但不是 OData V4 的问题。

复杂类型“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() 在 Microsoft.OneIM.ActiveIncident.Service.ModelBuilder.BuildIncidentModels() 在 c:\OneIM\EngSys\OneIM\ActiveIncident\src\Product\Service\Models\ModelBuilder.cs:line 42 在 Microsoft.OneIM.ActiveIncident.Service.WebApiConfig.Register(HttpConfiguration config) 在 c:\OneIM\EngSys\OneIM\ActiveIncident\src\Product\Service\App_Start\WebApiConfig.cs:line 22 在 Microsoft.OneIM.ActiveIncident.ServiceHost.ApiStartup.Configuration(IAppBuilder appBuilder) 在 c:\OneIM\EngSys\OneIM\ActiveIncident\src\Product\ServiceHost\ApiStartup.cs:line 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; }
}

【问题讨论】:

    标签: asp.net-web-api odata


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      您必须通过 [key] 属性或在模型构建器中将 key 属性设置为

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

      希望对你有帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-11-29
        • 2014-03-31
        • 1970-01-01
        • 1970-01-01
        • 2017-11-06
        • 1970-01-01
        • 2013-02-03
        相关资源
        最近更新 更多