本文整理汇总了C#中System.Data.Entity.Migrations.DbMigrator类的典型用法代码示例。如果您正苦于以下问题:C# DbMigrator类的具体用法?C# DbMigrator怎么用?C# DbMigrator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DbMigrator类属于System.Data.Entity.Migrations命名空间,在下文中一共展示了DbMigrator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DbMigratorEventArgs
public DbMigratorEventArgs(DbMigrationsConfiguration migrationConfiguration)
{
this.MigrationConfiguration = migrationConfiguration;
DbMigrator migrator = new DbMigrator(migrationConfiguration);
this.PendingMigrations = migrator.GetPendingMigrations();
this.CompletedMigrations = migrator.GetDatabaseMigrations();
}
示例2: RegisterAuth
public static void RegisterAuth()
{
var migrator = new DbMigrator(new Configuration());
migrator.Update();
if (!WebSecurity.Initialized)
{
WebSecurity.InitializeDatabaseConnection("AnunciosDbContext", "UserProfile", "UserId",
"UserName", autoCreateTables: true);
}
// To let users of this site log in using their accounts from other sites such as Microsoft, Facebook, and Twitter,
// you must update this site. For more information visit http://go.microsoft.com/fwlink/?LinkID=252166
//OAuthWebSecurity.RegisterMicrosoftClient(
// clientId: "",
// clientSecret: "");
//OAuthWebSecurity.RegisterTwitterClient(
// consumerKey: "",
// consumerSecret: "");
//OAuthWebSecurity.RegisterFacebookClient(
// appId: "",
// appSecret: "");
//OAuthWebSecurity.RegisterGoogleClient();
}
示例3: ConfigureMobileApp
public static void ConfigureMobileApp(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
//For more information on Web API tracing, see http://go.microsoft.com/fwlink/?LinkId=620686
config.EnableSystemDiagnosticsTracing();
new MobileAppConfiguration().UseDefaultConfiguration().ApplyTo(config);
// Use Entity Framework Code First to create database tables based on your DbContext
// Database.SetInitializer(new mouselightInitializer());
var migrator = new DbMigrator(new Janelia.Mouse.Mobile.Server.Migrations.Configuration());
migrator.Update();
// To prevent Entity Framework from modifying your database schema, use a null database initializer
// Database.SetInitializer<MouseLightContext>(null);
MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();
if (string.IsNullOrEmpty(settings.HostName))
{
// This middleware is intended to be used locally for debugging. By default, HostName will
// only have a value when running in an App Service application.
app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
{
SigningKey = ConfigurationManager.AppSettings["SigningKey"],
ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] },
ValidIssuers = new[] { ConfigurationManager.AppSettings["ValidIssuer"] },
TokenHandler = config.GetAppServiceTokenHandler()
});
}
app.UseWebApi(config);
}
示例4: RunUpdate
private static void RunUpdate(string connectionName)
{
Console.WriteLine("RUNNING MIGRATIONS FOR CONNECTION NAME: " + connectionName);
var configuration = new Configuration();
configuration.TargetDatabase =
new DbConnectionInfo(connectionName);
try
{
Console.WriteLine("TRYING...");
var migrator = new DbMigrator(configuration);
migrator.Update();
Console.WriteLine("SUCCESS!");
ExitCode = 1;
}
catch (Exception ex)
{
Console.WriteLine("EXCEPTION:");
Console.WriteLine(ex.Message);
Console.WriteLine("FAILURE!");
}
Console.WriteLine("DONE!");
Environment.Exit(ExitCode);
}
示例5: Main
public static void Main(string[] args)
{
Console.WriteLine(@"Migrating database...");
var migrator = new DbMigrator(new Configuration());
Console.WriteLine(@"Connection: " + GetConnectionString(migrator));
var migrations = migrator.GetPendingMigrations().ToList();
if (!migrations.Any()) {
Console.WriteLine(@"No pending migrations.");
} else {
foreach (var migration in migrations) {
Console.WriteLine(migration);
migrator.Update(migration);
}
}
if (args.Contains("--seed")) {
Console.WriteLine(@"Seeding the database...");
var context = new EntityContext();
DatabaseSeeder.Seed(context);
context.SaveChanges();
} else {
Console.WriteLine(@"No seeding required.");
}
Console.WriteLine(@"Migration done.");
}
示例6: InitializeDatabase
public void InitializeDatabase()
{
var configuration = new Configuration();
var migrator = new DbMigrator(configuration);
migrator.Update();
}
示例7: QueueFixture
public QueueFixture()
{
try
{
var configuration = new DbMigrationsConfiguration
{
ContextType = typeof(QueueDataContext),
MigrationsAssembly = typeof(QueueDataContext).Assembly,
TargetDatabase = new DbConnectionInfo("QueueDataContext"),
MigrationsNamespace = typeof(InitialCreate).Namespace,
AutomaticMigrationDataLossAllowed = true
};
var migrator = new DbMigrator(configuration);
//Update / rollback to "MigrationName"
migrator.Update("0");
migrator.Update();
_sut = new SqlQueueImpl(new Infrastructure.DatabaseContextFactory());
}
catch (Exception ex)
{
if (Debugger.IsAttached) Debugger.Break();
Console.WriteLine(ex);
throw;
}
}
示例8: RunMigrations
private static void RunMigrations()
{
var efMigrationSettings = new HomeManager.Domain.Migrations.Configuration();
var efMigrator = new DbMigrator(efMigrationSettings);
efMigrator.Update();
}
示例9: Application_Start
protected void Application_Start()
{
var connString = ConfigurationManager.ConnectionStrings["BlogContext"];
string commandText = @"
CREATE TABLE [__MigrationHistory] (
[Id] [uniqueidentifier] DEFAULT newid(),
[Migration] [nvarchar](255) NOT NULL,
[CreatedOn] [datetime] NOT NULL,
[Hash] [binary](32) NOT NULL,
[Model] [varbinary](max) NOT NULL,
PRIMARY KEY ([Id])
);
";
using (var connection = new SqlConnection(connString.ConnectionString)) {
using (var command = new SqlCommand(commandText, connection)) {
connection.Open();
try {
command.ExecuteNonQuery();
}
catch {
}
}
}
var dbMigrator = new DbMigrator(new MvcApplicationCodeFirst.Migrations.Settings());
dbMigrator.Update();
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
示例10: GetMigrator
public static DbMigrator GetMigrator(TestContext testContext)
{
var configuration = new Configuration();
configuration.TargetDatabase = new DbConnectionInfo("DefaultConnection");
var migrator = new DbMigrator(configuration);
return migrator;
}
示例11: CreateScriptFromMigration
public static string CreateScriptFromMigration()
{
var migrationConfig = new Configuration();
var migrator = new DbMigrator(migrationConfig);
var scriptor = new MigratorScriptingDecorator(migrator);
return scriptor.ScriptUpdate(sourceMigration: null, targetMigration: null);
}
示例12: Application_Start
protected void Application_Start()
{
var migrator = new DbMigrator(new Configuration());
migrator.Configuration.AutomaticMigrationDataLossAllowed = true;
migrator.Update();
//Database.SetInitializer<ApplicationDbContext>(new AppDbInitializer());
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
BundleMobileConfig.RegisterBundles(BundleTable.Bundles);
ModelBinders.Binders.Add(typeof(Cart), new CartModelBinder());
ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory());
DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("iphone")
{
ContextCondition = Context =>
Context.Request.Browser["HardwareModel"] == "iPhone"
});
DisplayModeProvider.Instance.Modes.Insert(1, new DefaultDisplayMode("android")
{
ContextCondition = Context =>
Context.Request.Browser["PlatformName"] == "Android"
});
DisplayModeProvider.Instance.Modes.Insert(2, new DefaultDisplayMode("mobile")
{
ContextCondition = Context =>
Context.Request.Browser["IsMobile"] == "True"
});
}
示例13: GenerateSqlUsingDbMigrator
public static void GenerateSqlUsingDbMigrator()
{
using (var context = new AdventureWorksContext())
{
var configuration = new Configuration
{
ContextType = typeof(AdventureWorksContext),
TargetDatabase =
new DbConnectionInfo(context.Database.Connection.ConnectionString, "System.Data.SqlClient")
};
var migrator = new DbMigrator(configuration);
var migrations = migrator.GetDatabaseMigrations();
if (migrations.Any())
{
var scriptor = new MigratorScriptingDecorator(migrator);
string script = scriptor.ScriptUpdate(null, migrations.Last());
if (!String.IsNullOrEmpty(script))
{
Console.WriteLine(script);
//context.Database.ExecuteSqlCommand(script);
}
}
Console.ReadKey();
}
}
示例14: Run
public static void Run()
{
ConsoleLogger.Information("Installing Database");
using (var context = new DataContext())
{
try
{
ConsoleLogger.Information(" Dropping database...");
context.Database.Delete();
}
catch (Exception ex)
{
ConsoleLogger.Error(" Error: Could not drop database! " + ex);
}
try
{
ConsoleLogger.Information(" Creating database...");
var migrator = new DbMigrator(new ClaimDbConfiguration());
migrator.Update();
}
catch (Exception ex)
{
ConsoleLogger.Error(" Error: Could not create database! " + ex);
}
}
ConsoleLogger.Information("Database Installed!");
}
示例15: MainContext
public MainContext(string connectionString)
: base(connectionString)
{
ConnectionString = connectionString;
_Migrator = new DbMigrator(this.GetDbMigrationsConfiguration());
logger = NLog.LogManager.GetCurrentClassLogger();
}