本文整理汇总了C#中System.Data.Entity.Migrations.DbMigrator类的典型用法代码示例。如果您正苦于以下问题:C# DbMigrator类的具体用法?C# DbMigrator怎么用?C# DbMigrator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DbMigrator类属于System.Data.Entity.Migrations命名空间,在下文中一共展示了DbMigrator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: DbMigratorEventArgs
public DbMigratorEventArgs(DbMigrationsConfiguration migrationConfiguration)
{
this.MigrationConfiguration = migrationConfiguration;
DbMigrator migrator = new DbMigrator(migrationConfiguration);
this.PendingMigrations = migrator.GetPendingMigrations();
this.CompletedMigrations = migrator.GetDatabaseMigrations();
}
开发者ID:TheOtherTimDuncan,项目名称:EntityFramework.DatabaseMigrator,代码行数:8,代码来源:DbMigratorEventArgs.cs
示例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();
}
开发者ID:Daesgar,项目名称:MisAnunciosMSFT,代码行数:27,代码来源:AuthConfig.cs
示例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);
}
开发者ID:TeravoxelTwoPhotonTomography,项目名称:acq-dashboard,代码行数:34,代码来源:Startup.MobileApp.cs
示例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);
}
开发者ID:dasklub,项目名称:kommunity,代码行数:28,代码来源:Program.cs
示例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.");
}
开发者ID:geirsagberg,项目名称:Reference,代码行数:29,代码来源:EntryPoint.cs
示例6: InitializeDatabase
public void InitializeDatabase()
{
var configuration = new Configuration();
var migrator = new DbMigrator(configuration);
migrator.Update();
}
开发者ID:justinconnell,项目名称:remi,代码行数:7,代码来源:PluginInitializer.cs
示例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;
}
}
开发者ID:RhysC,项目名称:SqlQueue,代码行数:26,代码来源:QueueFixture.cs
示例8: RunMigrations
private static void RunMigrations()
{
var efMigrationSettings = new HomeManager.Domain.Migrations.Configuration();
var efMigrator = new DbMigrator(efMigrationSettings);
efMigrator.Update();
}
开发者ID:rswafford,项目名称:HomeManager,代码行数:7,代码来源:EFConfig.cs
示例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);
}
开发者ID:davidebbo-test,项目名称:EFMigrationTest,代码行数:32,代码来源:Global.asax.cs
示例10: GetMigrator
public static DbMigrator GetMigrator(TestContext testContext)
{
var configuration = new Configuration();
configuration.TargetDatabase = new DbConnectionInfo("DefaultConnection");
var migrator = new DbMigrator(configuration);
return migrator;
}
开发者ID:alexdresko,项目名称:Proofted,代码行数:7,代码来源:DatabaseMigrations.cs
示例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);
}
开发者ID:jboyflaga,项目名称:StudInfoSys.MVC4.DomainCentric,代码行数:7,代码来源:MigrationConfigurationExecution.cs
示例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"
});
}
开发者ID:crew1248,项目名称:web_store,代码行数:33,代码来源:Global.asax.cs
示例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();
}
}
开发者ID:jeanhibbert,项目名称:EfTestConsole,代码行数:26,代码来源:EfDbMigrations.cs
示例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!");
}
开发者ID:krlloyd,项目名称:ClaimSystem,代码行数:29,代码来源:Installer.cs
示例15: MainContext
public MainContext(string connectionString)
: base(connectionString)
{
ConnectionString = connectionString;
_Migrator = new DbMigrator(this.GetDbMigrationsConfiguration());
logger = NLog.LogManager.GetCurrentClassLogger();
}
开发者ID:khimalex,项目名称:ContextWorker,代码行数:7,代码来源:MainContext.cs
示例16: Run
public string Run(string from, string to)
{
var configuration = new Configuration();
//Can set the Target Database to be in another Server or Environment
//configuration.TargetDatabase =
// new DbConnectionInfo("Server=.;Database=Investment;Trusted_Connection=True;",
// "System.Data.SqlClient");
//var context = (InvestmentContext)Activator.CreateInstance(configuration.ContextType);
var runUpdate = false;
var migrator = new DbMigrator(configuration);
var scriptor = new MigratorScriptingDecorator(migrator);
var sql = scriptor.ScriptUpdate("", "");
//var sql = scriptor.ScriptUpdate("Name-Of-Source-Migration", "Name-Of-Target-Migration");
//configuration.RunSeedProcess(context);
if (runUpdate)
{
//Can run the update from here
migrator.Update(); //Could add a "TargetMigration"
}
return sql;
}
开发者ID:ozcarzarate,项目名称:Asx,代码行数:27,代码来源:ScriptGenerator.cs
示例17: RunMigrations
private static void RunMigrations()
{
var efMigrationSettings = new ShippingExpress.Domain.Migrations.Configuration();
var efMigrator = new DbMigrator(efMigrationSettings);
efMigrator.Update();
}
开发者ID:hakeemsm,项目名称:ShippingExpress,代码行数:7,代码来源:EFConfig.cs
示例18: RunMigrations
private static void RunMigrations() {
var efMigrationSettings = new PingYourPackage.Domain.Migrations.Configuration();
var efMigrator = new DbMigrator(efMigrationSettings);
efMigrator.Update();
}
开发者ID:NikolayKostadinov,项目名称:PingYourPackage,代码行数:7,代码来源:EFConfig.cs
示例19: UpdateDb
private static void UpdateDb()
{
var settings = new Configuration();
var migrator = new DbMigrator(settings);
migrator.Update();
}
开发者ID:shahzadadil,项目名称:OnlineChatSupport,代码行数:7,代码来源:Global.asax.cs
示例20: CreateNewDatabase
/// <summary>
/// Creates a new database file at the specified path with the specified file name.
/// The ".sdf" extension will be added to the file. Do not pass it in the file name.
/// </summary>
/// <param name="databaseFilePath">The path to the file, excluding the file's name</param>
/// <param name="databaseFileName">The name of the new database file. Exclude the .sdf extension - it will be added automatically.</param>
/// <param name="changeApplicationConnection">If true, the application's connection will be changed to this new database.</param>
/// <returns>Returns the full path to the database file.</returns>
public string CreateNewDatabase(string databaseFilePath, string databaseFileName, bool changeApplicationConnection)
{
string fullPath = databaseFilePath + "\\" + databaseFileName + ".sdf";
string connectionString;
// Update connection settings and the active module directory path
if (changeApplicationConnection)
{
ChangeDatabaseConnection(fullPath);
WinterConnectionInformation.ActiveModuleDirectoryPath = fullPath;
connectionString = WinterConnectionInformation.ActiveConnectionString;
}
// Otherwise we're simply creating a new database file. Build a connection string.
else
{
connectionString = BuildConnectionString(fullPath);
}
// Initialize the database - will create the database file at the specified location.
// Also creates tables based on the code-first model.
using (ModuleDataContext context = new ModuleDataContext(connectionString))
{
DbMigrator migrator = new DbMigrator(new ModuleDataContextMigrationConfiguration());
migrator.Update();
}
return fullPath;
}
开发者ID:zunath,项目名称:WinterEngine,代码行数:36,代码来源:DatabaseRepository.cs
注:本文中的System.Data.Entity.Migrations.DbMigrator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论