标签: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