您的位置:首页 > 博客中心 > 数据库 >

Entity framework DB first---(1)

时间:2022-03-13 22:55

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

热门排行

今日推荐

热门手游