1. 引用EntityFramework.dll

2.创建数据库相关表名的类,eg:Product.cs/Categories.cs 等等

or

 

3.建个XXXContext.cs类(如:NorthwindContext.cs)

 


 4.配置Webconfig.cs连接数据库

<connectionStrings>

    <add name="NorthwindContext"
         connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\northwind.mdf;User Instance=true"
         providerName="System.Data.SqlClient" />

  </connectionStrings>

5.像使用Linq一样使用entityframework

如:

 public ActionResult Index()
        {
            var db = new NorthwindContext();
            var product = db.Products.FirstOrDefault();

            return View(product);
        }