I am getting the following exception when selecting Manage on Persisted Grants Tile in the Admin UI. I have followed all the steps to change the userid form int to string (not Guid since the database ASPNetusers has it as string)
InvalidOperationException: The property '' on entity type 'UserIdentity' could not be found. Ensure that the property exists and has been included in the model.
Please suggest. It fails on the following line..
var persistedGrantsData = await persistedGrantByUsers.WhereIf(!string.IsNullOrEmpty(search), searchCondition).PageBy(x => x.SubjectId, page, pageSize).ToListAsync();
in following method. Please note that in the debugger the persistedGrantByUsers seems to be fine with about 12 rows..... so I don't know what property it is looking for?
public async Task<PagedList<PersistedGrantDataView>> GetPersitedGrantsByUsers(string search, int page = 1, int pageSize = 10)
{
var pagedList = new PagedList<PersistedGrantDataView>();
var persistedGrantByUsers = (from pe in _dbContext.PersistedGrants
join us in _dbContext.Users on pe.SubjectId equals us.Id.ToString() into per
from us in per.DefaultIfEmpty()
select new PersistedGrantDataView
{
SubjectId = pe.SubjectId,
SubjectName = us == null ? string.Empty : us.UserName
})
.Distinct();
Expression<Func<PersistedGrantDataView, bool>> searchCondition = x => x.SubjectId.Contains(search) || x.SubjectName.Contains(search);
**var persistedGrantsData = await persistedGrantByUsers.WhereIf(!string.IsNullOrEmpty(search), searchCondition).PageBy(x => x.SubjectId, page, pageSize).ToListAsync();**
var persistedGrantsDataCount = await persistedGrantByUsers.WhereIf(!string.IsNullOrEmpty(search), searchCondition).CountAsync();
pagedList.Data.AddRange(persistedGrantsData);
pagedList.TotalCount = persistedGrantsDataCount;
pagedList.PageSize = pageSize;
return pagedList;
}
Hi, I've faced the same issue today.
I found some suggestions that there's a bug in EntitiFramework.Core which is appearing when there's SelectMany with Join in LINQ used.
As a workaround I've created my own persistantgrants repository class and replaced this phrase:
var persistedGrantByUsers = (from pe in _dbContext.PersistedGrants
join us in _dbContext.Users on pe.SubjectId equals us.Id.ToString() into per
from us in per.DefaultIfEmpty()
select new PersistedGrantDataView
{
SubjectId = pe.SubjectId,
SubjectName = us == null ? string.Empty : us.UserName
})
.Distinct();
with:
var persistedGrantByUsers = _dbContext.PersistedGrants
.Join(_dbContext.Users, pe => (object)pe.SubjectId, us => (object)us.Id, (grant, user) =>
new PersistedGrantDataView
{
SubjectId = grant.SubjectId ?? string.Empty,
SubjectName = user.UserName ?? string.Empty
}
).Distinct();
Casts of pe.SubjectId and us.id to object are needed to translate expression tree into SQL query. Without that most of LINQ is executed locally in memory.
Basically I've flattend structure (from subjectId->[user1, user2, user3] to [subjectId, user1] [subjectId, user2] [subjectId, user3].
This is maybe less efficient but at least it works for now.
Hi guys, thank you for reporting, I will check it. :)
Most helpful comment