AutoMapper / AutoMapper.Extensions.OData

Creates LINQ expressions from ODataQueryOptions and executes the query.
MIT License
140 stars 38 forks source link

Invalid operation since v3.0.2: NNN has not been declared in the entity data model #152

Closed BlaiseD closed 1 year ago

BlaiseD commented 1 year ago

Discussed in https://github.com/AutoMapper/AutoMapper.Extensions.OData/discussions/151

Originally posted by **dettner** September 19, 2022 _I am sorry if this is the wrong forum, please redirect me to the correct place, if that is the case._ With AutoMapper.AspNetCore.OData.EFCore 3.0.1, everything works(tm). When upgrading to v3.0.2 or later I get the exception below, whenever I add _any_ OData query to my OData resource (e.g. a simple "/?$top=1") `System.InvalidOperationException: The type 'CorrectFull.NameOfMyEDMType' has not been declared in the entity data model. at AutoMapper.AspNet.OData.ODataQueryContextExtentions.FindSortableProperties(ODataQueryContext context, Type type) at AutoMapper.AspNet.OData.LinqExtensions.GetQueryableMethod(Expression expression, ODataQueryContext context, OrderByClause orderByClause, Type type, Nullable'1 skip, Nullable'1 top) at AutoMapper.AspNet.OData.LinqExtensions.GetOrderByMethod[T](Expression expression, ODataQueryOptions'1 options, ODataSettings oDataSettings) at AutoMapper.AspNet.OData.LinqExtensions.GetQueryableExpression[T](ODataQueryOptions'1 options, ODataSettings oDataSettings) at AutoMapper.AspNet.OData.QueryableExtensions.GetQueryable[TModel,TData](IQueryable'1 query, IMapper mapper, ODataQueryOptions'1 options, QuerySettings querySettings, Expression'1 filter)` ... There are no other changes on my side except for the v3.0.1 -> v3.0.2 version upgrade. I have tried AutoMapper.AspNetCore.OData.EFCore v3.0.5 with the same result. I use .NET6, and I have the latest versions of everything else. The OData resource is defined like this: `var myBuilder = builder.Services.AddControllersWithViews() .AddOData(options => { options.AddRouteComponents("odataapi", Startup.BuildEdmModelForOData()).EnableQueryFeatures(); });` that static method is defined like this: `public static IEdmModel BuildEdmModelForOData() { var builder = new ODataConventionModelBuilder { Namespace = "CorrectFull" }; builder.EntitySet("NameOfMyEDMTypes"); var result = builder.GetEdmModel(); return result; }` I would really appreciate some help.