Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

UserRepository.FullName and IQueryable #10531


User avatar
0
BobIngham created
10.4.0 Angular, .NET Core

I have a queryable which I return to a Kendo DataSourceResult object for paging and querying for a grid:

private readonly IRepository<User, long> _userRepository
...

public IQueryable<NcFormSubmissionForKendoGridDto> GetFormSubmissionsForNcActionAudit()
        {
            var query = from formSubmission in _ncFormSubmissionRepository.GetAll()
                        join ncAction in _ncActionRepository.GetAll() on formSubmission.NcActionId equals ncAction.Id
                        join user in _userRepository.GetAll() on formSubmission.CreatorUserId equals user.Id
                        join ncEntity in _ncEntityRepository.GetAll() on formSubmission.NcEntityId equals ncEntity.Id
                        join organizationUnit in _organizationUnitRepository.GetAll() on ncEntity.OrganizationUnitId equals organizationUnit.Id
                        select new NcFormSubmissionForKendoGridDto
                        {
                            Id = formSubmission.Id,
                            CreationTime = formSubmission.CreationTime,
                            ClientCreatedDatetime = formSubmission.ClientCreatedDatetime,
                            ReportString = formSubmission.ReportString,
                            SerializedJson = formSubmission.SerializedJson,
                            CreatedByFullName = user.UserName,
                            NcActionDisplayName = ncAction.DisplayName,
                            NcEntityDisplayName = ncEntity.DisplayName,
                            OrganizationUnitDisplayName = organizationUnit.DisplayName,
                        };
            return query;
        }

Ideally I would like the full name of the user: CreatedByFullName = user.FullName However this throws the following error message:

Translation of member 'FullName' on entity type 'User' failed. This commonly occurs when the specified member is unmapped. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

Is this a bug or is there anything which can be done about it? I could iterate the data after converting to a DataSourceResult but thought there may be a cleaner way.

Cheers, Bob


4 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @bobingham

    I think EF Core doesn't allow using notmapped fields in queries. You can define Name and Surname fields in your Dto first, then set them şn your query. You can also define a FullName field in your Dto and use it.

    public string FullName { get { return this.Name + " " + this.Surname; } }
    
  • User Avatar
    0
    BobIngham created

    Hi all,

    I have gone with the following: CreatedByFullName = user.Name + " " + user.Surname It would be interesting to know why user.FullName fails, however.

    Cheers, Bob

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I think this is the document which explains it https://docs.microsoft.com/en-us/ef/core/querying/client-eval.

  • User Avatar
    0
    BobIngham created

    Brilliant, thanks @ismcagdas.