Entity framework DB first---(1)

Db first 系列-1

1) 创建Db 文件,并指定connectionstring name:

 public class Db : DbContext
    {
        public Db()
            : base("prodinner")
        {

        }

        public DbSet<Country> Countries { get; set; }
        public DbSet<Chef> Chefs { get; set; }
        public DbSet<Meal> Meals { get; set; }
        public DbSet<Dinner> Dinners { get; set; }
        public DbSet<User> Users { get; set; }
        public DbSet<Role> Roles { get; set; }
        public DbSet<Feedback> Feedbacks { get; set; }
    }

2) 调用 Db class in your controller

  public ActionResult Index()
        {
            var result = from d in dbContext.Dinners
                         select d;

            return View(result);
        }

3) 在web.config 中添加Connectionstring

 <add name="prodinner" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=DB name;Integrated Security=True"
      providerName="System.Data.SqlClient" />

 

Entity framework DB first---(1),布布扣,bubuko.com

Entity framework DB first---(1)

上一篇:yum error: TypeError: rpmdb open failed


下一篇:Windows下搭建PHP开发环境,整合Apache+PHP+MySQL(举例软件为32位)