简体   繁体   中英

EF CodeFirst referencing DbContext Class

I created an empty C# Project in Visual Studio, and added a class. Then I added a reference to the System.Data.Entity dll. I added a class to my project and proceeded to write me a DbContext Object as below. However, I get the following error message. What other dlls do I need to reference in order to use this?

Error 1 The type or namespace name 'DbContext' does not exist in the namespace 'System.Data.Entity' (are you missing an assembly reference?)

using System; 
using System.Linq; 
using System.Threading.Tasks;
using System.Data.Entity; 

namespace Budget.Data
{
    public class BudgetContext : System.Data.Entity.DbContext
    {

    }
}

DbContext exists in a newer version of EntityFramework, so you need to download a newer version (or use nu-get to get it). The dll is called EntityFramework.dll

Followed the instructions from this page . If it's new project, step 1 should be sufficient. But in case you have existing projects you are trying to update in the future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM