为什么System.Data.Entity不允许访问DbContext类/方法。 C#Visual Studio社区2013 [英] Why do System.Data.Entity not give access to DbContext class/method. C# Visual Studio Community 2013

查看:89
本文介绍了为什么System.Data.Entity不允许访问DbContext类/方法。 C#Visual Studio社区2013的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用System.Data.Entity;



命名空间Shop.Models

{

公共类ProductionContext : DbContext

{

public DbSet < spareparts>零件{get; set;}

....

}

}



//获取以下信息形成下划线:

//找不到类型或命名空间'DbContext'(您是否缺少使用//指令或汇编引用?)

using System.Data.Entity;

namespace Shop.Models
{
public class ProductionContext : DbContext
{
public DbSet<spareparts> parts {get;set;}
....
}
}

//Getting following msg. form the underlined:
//The type or namespace 'DbContext' could not be found (are you missing a using //directive or an assembly reference?)

推荐答案

DbContext 类实际上存在于EntityFramework.dll中,因此您需要添加对它的引用。您可以通过将Entity Framework NuGet包添加到项目中来轻松完成此操作。



https://msdn.microsoft.com/en-us/library/system.data.entity.dbcontext%28v=vs。 113%29.aspx [ ^ ]
The DbContext class actually lives in the EntityFramework.dll so you need to add reference to that. You can easily do this by adding the Entity Framework NuGet package to your project.

https://msdn.microsoft.com/en-us/library/system.data.entity.dbcontext%28v=vs.113%29.aspx[^]


这篇关于为什么System.Data.Entity不允许访问DbContext类/方法。 C#Visual Studio社区2013的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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