数据访问方式之EntityFramework(1)

  1. 新建web应用程序 数据访问方式之EntityFramework(1)数据访问方式之EntityFramework(1)
  2. 新建DAL文件夹,添加新建项>Data>ADO.NET实体数据模型DBContext
    数据访问方式之EntityFramework(1)
    数据访问方式之EntityFramework(1)
    数据访问方式之EntityFramework(1)
    数据访问方式之EntityFramework(1)
  3. 上一步操作得到以下结果:
    1. 自动添加EntityFramework引用
    2. Web.Config中添加数据连接
    3. 添加数据访问上下文
    4. 以及数据库 Model
 <connectionStrings>
   <add name="DBConn" connectionString="data source=.;initial catalog=ClayDataBase;persist security info=True;user id=sa;password=sa;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
 </connectionStrings>
   public partial class DBContext : DbContext
   {
       public DBContext() : base("name=DBConn") { }

       public virtual DbSet<Customer> Customer { get; set; }
       public virtual DbSet<Product> Product { get; set; }

       protected override void OnModelCreating(DbModelBuilder modelBuilder) { }
   }