Chủ Nhật, 3 tháng 4, 2016

Các bước tạo website code first

1. create model
2. Create the Database Context
3. Edit connection string
connectionString="Data Source=.\sqlexpress;Initial Catalog=ContosoUniversity2;Integrated Security=True" providerName="System.Data.SqlClient" />
4.
Install-Package EntityFramework
Enable-Migrations
add-migration
update-database
var tables = new List

{
new Table { Id = 1, Name = "Carson",   seat = 4, },
new Table { Id = 2, Name = "Meredith", seat = 4  },
new Table { Id = 3, Name = "Arturo",   seat = 2  },  
new Table { Id = 4, Name = "Gytis",    seat = 2  }

};
tables.ForEach(s => context.Tables.AddOrUpdate(p => p.Name, s));
context.SaveChanges();

Không có nhận xét nào:

Đăng nhận xét