????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();
????}