值不能为空.参数名称:entitySet [英] Value cannot be null. Parameter name: entitySet

查看:32
本文介绍了值不能为空.参数名称:entitySet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当标准的设置,只有 POCO 类

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; }
}

他们使用一个接口

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

并被构建为ninject绑定到的存储库

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; }
    }
}

实际的上下文只是一个简单的 DbContext

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

我已经在其他项目中完成了这个确切的过程,并且从未出现过错误.这是连接到本地 Sql Server 数据库.连接字符串似乎没有问题.我在网上搜索过这个错误,但解决方案似乎回答了与我的设置没有直接关系的问题.

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.

推荐答案

如果未在 DbContext 中声明其中一个 POCO 类,则会出现此问题.

我添加了它们,错误消失了

I added them and the error went away

我更改了 Task POCO 类的名称,因为它与内置的 .NET 名称 System.Threading.Tasks 相关联.但是,我没有在存在关系的TaskTimeLog"POCO 中更改此设置.在检查代码时,TaskTimeLog"POCO 中的Task"属性没有显示错误,因为它现在附加到该线程关键字以及我首先更改名称的原因.

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.

这篇关于值不能为空.参数名称:entitySet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆