Value cannot be null. Parameter name: entitySet

前端 未结 12 1863
夕颜
夕颜 2020-12-03 17:02

I have a fairly standard setup with simply POCO classes

public class Project
{

    public int ProjectId { get; set; }
    public string Name { get; set; }
          


        
12条回答
  •  感动是毒
    2020-12-03 17:20

    I got this error:

    Value cannot be null. Parameter name: entitySet

    Turns out I was trying to join data from 2 different DbContexts.

            var roles = await _identityDbContext.Roles
                .AsNoTracking()
                .Take(1000)
                .Join(_configurationDbContext.Clients.ToList(),
                    a => a.ClientId,
                    b => b.Id,
                    (a,b) => new {Role = a, Client = b})
                .OrderBy(x => x.Role.ClientId).ThenBy(x => x.Role.Name)
                .Select(x => new RoleViewModel
                {
                    Id = x.Role.Id,
                    Name = x.Role.Name,
                    ClientId = x.Role.ClientId,
                    ClientName = x.Client.ClientName
                })
                .ToListAsync();
    

    The fix is to add ToList as shown. Then the join will happen in code instead of the database.

    Only do this if you are OK with retrieving the whole table. (I know my "Clients" table will always be relatively small.)

提交回复
热议问题