OData V4 .NET Core AutoMapper nested properties cannot be translated from Linq

Skip to first unread message


May 7, 2020, 9:43:14 AM5/7/20
to AutoMapper-users

I am trying to get the OData Query "orderby" on a nested property to work on .Net Core 3.1

According to my reading the correct query should be formatted like this:


and I get the following error message:

System.InvalidOperationException: The LINQ expression 'DbSet<Entity>
          outer: DbSet<User>,
        inner: p => EF.Property<Nullable<Guid>>(p, "OwnById"), outerKeySelector: u => EF.Property<Nullable<Guid>>(u, "UserId"),
        innerKeySelector: (o, i) => new TransparentIdentifier<Portfolio, User>(
            Outer = o,
            Inner = i
    .OrderBy(p => EF.Property<Nullable<Guid>>(p.Inner, "UserId") == null ? null : new UserModel{
        UserEmail = p.Inner.UserEmail,
        UserFirstName = p.Inner.UserFirstName,
        UserId = p.Inner.UserId,
        UserLastName = p.Inner.UserLastName,
        Username = p.Inner.Username
could not be translated.

It seems to be a fairly simple example, but the linq query seems to be mixing BbSet entity with DtoEntity which may come from AutoMapper.

Here is my controller using AutoMapper:

[ProducesResponseType(typeof(ODataValue<IEnumerable<EntityModel>>), Status200OK)]
[EnableQuery(AllowedQueryOptions = All, MaxTop = 100)]
public IQueryable<EntityModel> Get()
var results = _Query.Get();
return results.ProjectTo<EntityModel>(_Mapper.ConfigurationProvider);

AutoMapper config:

CreateMap<Entity, EntityModel>();

<EntityType Name="EntityModel">
<PropertyRef Name="entityId" />
<Property Name="ownById" Type="Edm.Guid" />
<NavigationProperty Name="ownBy" Type="AMI.UserModel" />

<EntityType Name="UserModel">
<PropertyRef Name="userId" />
<Property Name="userId" Type="Edm.Guid" Nullable="false" />
<Property Name="username" Type="Edm.String" />
<Property Name="userFirstName" Type="Edm.String" />
<Property Name="userLastName" Type="Edm.String" />
<Property Name="userEmail" Type="Edm.String" />

Any hint would be very much appreciated

Jimmy Bogard

May 7, 2020, 11:45:57 AM5/7/20
to automapp...@googlegroups.com

There’s a NuGet package explicitly for OData and expression mapping, have you looked at that?



You received this message because you are subscribed to the Google Groups "AutoMapper-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to automapper-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/automapper-users/96ea9942-23c6-42bf-8065-47e057618785%40googlegroups.com.


Reply all
Reply to author
0 new messages