public SimpleMembershipInitializer() { Database.SetInitializer <UsersContext>(null); try { using (var context = new UsersContext()) { if (!context.Database.Exists()) { // Create the SimpleMembership database without Entity Framework migration schema ((IObjectContextAdapter)context).ObjectContext.CreateDatabase(); } } WebSecurity.InitializeDatabaseConnection("SecurityDb", "UserProfile", "UserId", "UserName", autoCreateTables: true); } catch (Exception ex) { throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex); } using (var context = new LiteDispatchDbContext(new ModelCreator())) { if (context.Database.Exists()) { return; } context.Database.CreateIfNotExists(); using (var transManager = Container.GlobalContext.TransFactory.CreateManager()) { transManager.ExecuteCommand(locator => { var haulier = locator.FindAll <Haulier>().SingleOrDefault(h => h.Name == "BlueWhale"); if (haulier != null) { return(Mapper.Map <Haulier, HaulierModel>(haulier)); } haulier = Haulier.Create(locator, new HaulierModel { Name = "BlueWhale" }); return(Mapper.Map <Haulier, HaulierModel>(haulier)); }); } } }
public void Install() { EntityToModel.Install(); ModelToEntity.Install(); var factory = new TransManagerFactoryEF(ModelCreator); using (var transManager = factory.CreateManager()) { transManager.ExecuteCommand(locator => { var haulier = locator.FindAll <Haulier>().SingleOrDefault(h => h.Name == "BlueWhale"); if (haulier != null) { return(Mapper.Map <Haulier, HaulierModel>(haulier)); } haulier = Haulier.Create(locator, new HaulierModel { Name = "BlueWhale" }); return(Mapper.Map <Haulier, HaulierModel>(haulier)); }); } }