码迷,mamicode.com
首页 > 数据库 > 详细

Entity framework DB first---(1)

时间:2014-08-21 16:46:34      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   文件   ar   div   cti   

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)

标签:style   blog   color   io   文件   ar   div   cti   

原文地址:http://www.cnblogs.com/Luxuan/p/3927264.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!