sammym
sammym

Reputation: 105

WebAPI AND Odata V4 issue: ComplexType containing Entities

I am getting following error while adding relationship inside the complex type. How can I fix this issue. I binged and read that it was issue with OData V3 but not in OData V4.

The complex type 'Microsoft.OneIM.ActiveIncident.Contracts.IncidentImpact' refers to the entity type 'Microsoft.OneIM.ActiveIncident.Contracts.ImpactedService' through the property 'ImpactedServices'.

at System.Web.OData.Builder.ODataConventionModelBuilder.MapComplexType(ComplexTypeConfiguration complexType) at System.Web.OData.Builder.ODataConventionModelBuilder.MapType(StructuralTypeConfiguration edmType) at System.Web.OData.Builder.ODataConventionModelBuilder.AddComplexType(Type type) at System.Web.OData.Builder.ODataConventionModelBuilder.ReconfigureEntityTypesAsComplexType(EntityTypeConfiguration[] misconfiguredEntityTypes) at System.Web.OData.Builder.ODataConventionModelBuilder.RediscoverComplexTypes() at System.Web.OData.Builder.ODataConventionModelBuilder.GetEdmModel() at Microsoft.OneIM.ActiveIncident.Service.ModelBuilder.BuildIncidentModels() in c:\OneIM\EngSys\OneIM\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 Microsoft.OneIM.ActiveIncident.ServiceHost.ApiStartup.Configuration(IAppBuilder appBuilder) in c:\OneIM\EngSys\OneIM\ActiveIncident\src\Product\ServiceHost\ApiStartup.cs:line 27

My model looks as below

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

Upvotes: 2

Views: 1669

Answers (2)

Maya
Maya

Reputation: 836

Although OData protocol V4 support complex type contains entity as navigation property, both of OData Lib and WebAPI OData do not implementation this feature now.

Upvotes: 2

ing.alfano
ing.alfano

Reputation: 436

You have to set a key property by [key] attribute or in the model builder as

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

Hope it helps.

Upvotes: 0

Related Questions