Value cannot be null. Parameter name: entitySet

ef-migrations entity-framework


I have a fairly standard setup with simply POCO classes

public class Project

    public int ProjectId { get; set; }
    public string Name { get; set; }
    public int? ClientId { get; set; }
    public virtual Client Clients { get; set; }

They use an interface

public interface IProjectRepository
    IEnumerable<Project> Projects { get; }

and are constructed as a repository for ninject to bind to

public class EFProjectRepository : IProjectRepository
    private EFDbContext context = new EFDbContext();

    public IEnumerable<Project> Projects
        get { return context.Projects; }

The actual context is a simply DbContext

public class EFDbContext : DbContext
    public DbSet<Project> Projects { get; set; }

When I try and enable code first migrations I get the following error

image of error

I have done this exact process with other projects and there as never been an error. This is connecting to a local Sql Server Database. There does not seem to be a problem with the connection string. I have searched for this error online but the solutions seem to answer questions that do not directly relate to my setup.

5/5/2017 10:24:30 AM

Accepted Answer

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.

2/20/2018 3:47:41 PM

Popular Answer

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

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow