Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Value cannot be null. Parameter name: entitySet

I had the same issue and the cause was a POCO class that had a property of type Type.


Late to the game...but if it helps...

I had this same problem, everything was working fine, but this issue appeared, I added the following to one of my classes

public HttpPostedFileBase File { get; set; }

which seemed to break it.

I ensured I didn't map this to the database by using the following:

[NotMapped]
public HttpPostedFileBase File { get; set; }

You need to add the following using statement:

using System.ComponentModel.DataAnnotations.Schema;

Hope this helps


This problem can occur if one of the POCO classes was not declared in the DbContext.

I added them and the error went away

I had changed the name of the Task POCO class because of its association with a built in .NET name System.Threading.Tasks. However I had not changed this in the "TaskTimeLog" POCO where there was a relation. When going through the code the "Task" property in the "TaskTimeLog" POCO was not showing an error because it was now attached to that threading keyword and the reason I had changed the name in the first place.


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.)


For anyone not finding a resolution in the other answers, I got this error when I created a derived class from a class that had an instance in some model. The exception occurred on the first usage of my context in a request.

This is a stripped-down example that will reproduce the behaviour. Model is a DbSet in my context.

public class Model
{
    public int Id { get; set; }
    public Duration ExposureDuration { get; set; }
}

public class Duration
{
    public int Value { get; set; }
    public string Unit { get; set; }
}

//Adding this will cause the exception to occur.
public class DurationExtended : Duration
{ }

This happened during work in progress. When I changed the model property ExposureDuration to type DurationExtended, all was working again.