In the CApp:
Database.SetInitializer(new InitDb());
var db = new EvlContext1();
var evl = new DbEventLog
{
Name = "GS.Trade.EventLog",
Alias = "GS.Trade.EventLog",
Code = "GS.Trade.EventLog",
Description = "GS.Trade.EventLog",
};
db.EventLogs.Add(evl);
db.SaveChanges();
In the Database Project
public class InitDb : DropCreateDatabaseIfModelChanges<ConfigurationContext>
{
protected override void Seed(ConfigurationContext db)
{
}
}
public class Initializer : DropCreateDatabaseIfModelChanges<EvlContext1>
{
protected override void Seed(EvlContext1 db)
{
Console.WriteLine("Initialize DataBase");
var evl = new DbEventLog
{
Name = "GS.Trade.EventLog",
Alias = "GS.Trade.EventLog",
Code = "GS.Trade.EventLog",
Description = "GS.Trade.EventLog",
};
db.EventLogs.Add(evl);
db.SaveChanges();
}
}
Database.SetInitializer(new InitDb());
var db = new EvlContext1();
var evl = new DbEventLog
{
Name = "GS.Trade.EventLog",
Alias = "GS.Trade.EventLog",
Code = "GS.Trade.EventLog",
Description = "GS.Trade.EventLog",
};
db.EventLogs.Add(evl);
db.SaveChanges();
In the Database Project
public class InitDb : DropCreateDatabaseIfModelChanges<ConfigurationContext>
{
protected override void Seed(ConfigurationContext db)
{
}
}
public class Initializer : DropCreateDatabaseIfModelChanges<EvlContext1>
{
protected override void Seed(EvlContext1 db)
{
Console.WriteLine("Initialize DataBase");
var evl = new DbEventLog
{
Name = "GS.Trade.EventLog",
Alias = "GS.Trade.EventLog",
Code = "GS.Trade.EventLog",
Description = "GS.Trade.EventLog",
};
db.EventLogs.Add(evl);
db.SaveChanges();
}
}
Комментариев нет:
Отправить комментарий