C# 命名空间中不存在类型或命名空间名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10140931/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 12:36:38  来源:igfitidea点击:

type or namespace name does not exist in the namespace

c#

提问by user1300580

I have the code below in a .cs file and I am coming across the errors below, any help would be appreciated.

我在 .cs 文件中有下面的代码,我遇到了下面的错误,任何帮助将不胜感激。

using System.Data.Entity;

namespace Assignment2.Models
{
    public class TicketBookingEntities : DbContext
    {
        public DbSet<Performance> Performances { get; set; }
        public DbSet<Production> Productions { get; set; }
    }
}

Errors:

错误:

Error   1   The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
Error   2   The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?)
Error   3   The type or namespace name 'DbSet' could not be found (are you missing a using directive or an assembly reference?)
Error   4   The type or namespace name 'DbSet' could not be found (are you missing a using directive or an assembly reference?)

采纳答案by Daniel Hilgarth

Make sure your project contains a reference to EntityFramework.dll.
See the topic To add a reference in Visual C#in this linkif you don't know how to add a reference.

确保您的项目包含对EntityFramework.dll的引用。如果您不知道如何添加引用,
请参阅此链接中的主题在 Visual C#中添加引用。

回答by Nikhil Agrawal

Try looking for your missing references in Object Browser.

尝试在对象浏览器中查找丢失的引用。