OData / WebApi

OData Web API: A server library built upon ODataLib and WebApi
https://docs.microsoft.com/odata
Other
853 stars 476 forks source link

Microsoft.OData.ModelBuilder 1.0.6 incompatible with Microsoft.AspNetCore.OData 7.5.8 #2503

Open chrisspre opened 3 years ago

chrisspre commented 3 years ago

I have a small project in <TargetFramework>net6.0</TargetFramework> and include the following two packages.

    <PackageReference Include="Microsoft.AspNetCore.OData" Version="7.5.8" />
    <PackageReference Include="Microsoft.OData.ModelBuilder" Version="1.0.6" />

The code

    var houses= builder.EntitySet<House>("houses");
    houses.HasCountRestrictions().IsCountable(true);

does not compile with error

'EntitySetConfiguration<House>' does not contain a definition for 'HasCountRestrictions' and no accessible extension method  ... 

Adding using Microsoft.OData.ModelBuilder; gives error:


'ODataConventionModelBuilder' is an ambiguous reference between 'Microsoft.AspNet.OData.Builder.ODataConventionModelBuilder' and 'Microsoft.OData.ModelBuilder.ODataConventionModelBuilder' [azf]csharp(CS0104)
xuzhg commented 3 years ago

Microsoft.AspNetCore.OData 7.5.8 includes the built-in model builder. Microsoft.OData.ModelBuilder is separated from Microsoft.OData.ModelBuilder 7.x and includes the same class names.

you can use the full type name, for example: "Microsoft.OData.ModelBuilder.ODataConventionModelBuilder" to get rid of the ambiguous.

habbes commented 3 years ago

@chrisspre did Sam's advice resolve the issue?

chrisspre commented 3 years ago

I got this from https://docs.microsoft.com/en-us/odata/webapi/model-builder-capabilities-vocabulary

@xuzhg the key is to be able to use the extension method houses.HasCountRestrictions().IsCountable(true); on the EntityTypeConfiguration returned by the WebAPI's ModelBuilder .

But I also need to start with Microsoft.AspNetCore.OData.Builder.ODataConventionModelBuilder for the comple ASP.NET infrastructure, right?

Is there an equivalent in Microsoft.OData.ModelBuilder 7.x a to add capability annotations ?

chrisspre commented 3 years ago

Just tried and this is working fine for me Issue can be closed from my side.