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)
-
0
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; } }
-
0
Hi all,
I have gone with the following:
CreatedByFullName = user.Name + " " + user.Surname
It would be interesting to know whyuser.FullName
fails, however.Cheers, Bob
-
0
Hi,
I think this is the document which explains it https://docs.microsoft.com/en-us/ef/core/querying/client-eval.
-
0
Brilliant, thanks @ismcagdas.