3.EF Code First
  3.1新增
public bool Build()
{
try
{
var context = new FeeDbContext();
if (!context.Database.Exists())
{
new List<IDataInitializer<GDG_DbContext>>() {
new DataInit()
}.Setup<GDG_DbContext>(context);
return true;
}
return false;
}
catch (DbEntityValidationException ex)
{
StringBuilder error = new StringBuilder();
foreach (var item in ex.EntityValidationErrors)
{
foreach (var item2 in item.ValidationErrors)
{
error.Append(string.Format("{0}:{1} ", item2.PropertyName, item2.ErrorMessage));
}
}
Console.WriteLine("数据库初始化报错:" + error);
throw ex;
}
catch (Exception e)
{
Console.WriteLine("数据库初始化报错:" + e.Message);
throw e;
}
}
  3.2移除
public bool Remove()
{
var context = new GDG_DbContext();
try
{
if (context.Database.Exists())
{
return context.Database.Delete();
}
return true;
}
catch (Exception e)
{
Console.WriteLine("数据库初始化报错:" + e.Message);
return false;
}
finally { context.Dispose(); }
}
  3.3初始化
  public bool Rebuild()
  {
  return Remove() && Build();
  }