Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FindSortableProperties - The type '{type.FullName}' has not been declared in the entity data model. #194

Open
fmclopes opened this issue Oct 18, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@fmclopes
Copy link

Hello,

I have find a problem when using the method GetQueryAsync. When I use this method give the error "The type 'Module1.CountryDto' has not been declared in the entity data model."

I have a EDM Model with 2 Dto with the same name but in different modules:

  • Module1.CountryDto
  • Module2.CountryDto

The method FindSortableProperties have a function called GetEntity the find by name, but I think it should be by full name. In my case the entities.Count will give 2 and will return null.

IEdmEntityType GetEntity()
{
    List<IEdmEntityType> entities = context.Model.SchemaElements.OfType<IEdmEntityType>().Where(e => e.Name == type.Name).ToList();
    if (entities.Count == 1)
        return entities[0];

    return null;
}

Note: when i use $orderBy it work because not call the method FindSortableProperties.

Version

AutoMapper.AspNetCore.OData.EFCore 4.0.0

Expected behavior

No error.

Actual behavior

Request results in status code 500 Internal Server Error with argument exception:

The type 'Module1.Country' 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)
   at AutoMapper.AspNet.OData.QueryableExtensions.<GetQueryAsync>d__2`2.MoveNext()
@BlaiseD
Copy link
Member

BlaiseD commented Oct 19, 2023

The comparison by name fixes issues #149 and #152. We could still check for FullName if there's more than result. Maybe:

            IEdmEntityType GetEntity()
            {
                List<IEdmEntityType> entities = context.Model.SchemaElements.OfType<IEdmEntityType>().Where(e => e.Name == type.Name).ToList();
                if (entities.Count == 1)
                    return entities[0];

                if (entities.Count > 1)
                    return entities.FirstOrDefault(e => e.FullName() == type.FullName);

                return null;
            }

or whatever works for the full name comparison.

PRs are welcome.

@BlaiseD BlaiseD added the bug Something isn't working label Oct 20, 2023
@QvAchthoven
Copy link

Hi,

We are currently facing this same issue.
For debugging purpose I included the Automapper.Extensions.OData sources in our project and implemented the 'count > 1, check FullName' suggested above and it works like a charm in our situation.

I've tried adding a duplicate class name to this repo in both the DAL.EFCore and Domain.OData projects in hopes of getting the issue to be reproducible (and thus testable/fixable), but I've yet to get any of the unit tests to fail as a result of this.

All tests succeed both with and without the 'check FullName if' implemented.

Do you have any suggestions to proceed?

@BlaiseD
Copy link
Member

BlaiseD commented Nov 2, 2024

I think you may have to assign a custom namespace to the builder. Here's a test doing that. Issues #149 and #152 might also shed some light.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants