?????????????????????

 

using BlogASPNET5.Entity.Accounts;
using BlogASPNET5.Repository.Contexts;
using System.Linq;
namespace BlogASPNET5.Repository.Migrations
{
public static class SampleData
{
static EFContext db = new EFContext();
public static void SetData()
{
db.Database.EnsureDeleted();
db.Database.EnsureCreated();
db.Add(
new Role { Name = "manage"?? Description = "?????" }??
new Role { Name = "member"?? Description = "???" });
db.SaveChanges();
//CoreCLR???????????????
for (int i = 1; i <= 1000; i++)
{
db.Add(
new User
{
Name = "admin" + i??
Password = "abc" + i??
Gender = Gender.man??
Role = db.Roles.Single(r => r.Name == "manage")
});
db.SaveChanges();
}
for (int i = 1; i <= 1000; i++)
{
db.Add(
new User
{
Name = "member" + i??
Password = "efg" + i??
Gender = Gender.woman??
Role = db.Roles.Single(r => r.Name == "member")
});
db.SaveChanges();
}
}
}
}

????1.3????
??????????????????

 

using BlogASPNET5.Repository.Contexts;
using BlogASPNET5.Repository.Migrations;
using System;
namespace BlogASPNET5.ConsoleApp
{
public class Program
{
public void Main(string[] args)
{
//??????????????????????
SampleData.SetData();
Console.WriteLine("set data OK!");
Console.ReadLine();
using (var db = new EFContext())
{
var lists = db.Users;
foreach (var item in lists)
{
Console.WriteLine(item.Name);
}
}
Console.ReadLine();
}
}
}

??????????????? EF7 beta2????????????????????????????MigrationHistory??????????????????
????2.С??
???????????????????????????????????????????