ef-migrations

EF Code First DbMigration without nuget

风流意气都作罢 提交于 2019-11-29 01:47:52
How to migrate DB without nuget? It is not possible to use Visual Studio with nuget in production environment. Currently, many examples only teach us to use Visual Studio with nuget. How to use the generated DbMigration classes? The easiest way is: Database.SetInitializer( new MigrateDatabaseToLatestVersion<MyDbContext, MyDbMigrationsConfiguration>()); This will run the migrations when initializing the DbContext. You can also force the execution manually: var migrator = new DbMigrator(new MyMigrationsConfiguration()); migrator.Update(); (I believe you also have to set TargetDatabase on the

“Execute Code First Migrations” checkbox disappeared from my publish profile

只愿长相守 提交于 2019-11-29 01:38:06
I'm using web deploy to deploy an MVC4 application using EF5 code first. I made a publish profile called "development" that uses web deploy for application and database using the 'Execute Code First Migrations' checkbox to run migrations on application startup. The publishing worked great for a while. At some point I added a new publish profile called "test" to deploy to another server, which uses the ftp method of deploy and no automatic migrations. This works fine too. However, when I tried to use my old "development" publish profile again, VS changes the settings automatically to the

How to apply migrations from code (EF Core)

核能气质少年 提交于 2019-11-29 01:28:01
How to apply migrations from code for EF6 work code Database.SetInitializer<CmContext>(null); var settings = new MigrationsConfiguration(); var migrator = new DbMigrator(settings); migrator.Update(); how to make similar in EF Core? In beta 7 and on, use: using Microsoft.Data.Entity; ... context.Database.Migrate(); For Entity Framework Core 1.0.0, ensure you have the Microsoft.EntityFrameworkCore.Relational NuGet package. Then import this namespace: using Microsoft.EntityFrameworkCore; Finally, get hold of a DbContext and run: context.Database.Migrate(); 来源: https://stackoverflow.com/questions

Create Table, Run Time using entity framework Code-First

风格不统一 提交于 2019-11-29 00:24:45
Is that possible to create table in run time by using EF Code-first? i could create my models class in run time by using C# CodeDOM(reflection) but i couldn't set the dbSet properties of my Dbcontext class in run time. whats your idea? whats the best solution to create table dynamically in run time?... some ones said to my that the only way is using classic ADO.Net . Sampath Yes,you can do that. You can do that using Finding the Classes : [AttributeUsage(AttributeTargets.Class)] public class PersistentAttribute : Attribute { } Now you can add some logic to the OnModelCreating method of your

EF 5 Code First Migration Bulk SQL Data Seeding

戏子无情 提交于 2019-11-28 23:16:51
问题 I am using EF5 with MVC4. The problem is that I have large data in my DB which I already imported from legacy DB. I want to load seed that data when model changes. My question is how can I seed large amount of data that is already in my DB? internal sealed class Configuration : MigrationsConfiguration<VoiceLab.Models.EFDataContext> { public Configuration() { AutomaticMigrationsEnabled = true; } protected override void Seed(VoiceLab.Models.EFDataContext context) { //what to do here to seed

What is the correct use of IDatabaseInitializer in EF?

我只是一个虾纸丫 提交于 2019-11-28 22:08:52
问题 I have a custom DatabaseInitialiser which is below /// <summary> /// Implements the IDatabaseInitializer to provide a custom database initialisation for the context. /// </summary> /// <typeparam name="TContext">TContext is the DbContext</typeparam> public class ParikshaDataBaseInitializer<TContext> : IDatabaseInitializer<TContext> where TContext : DbContext { /// <summary> /// The method to Initialise the database. /// Takes care of the database cannot be dropped since it is in use problem

How to set the isolation level for Entity Framework CodeFirst Migrations

 ̄綄美尐妖づ 提交于 2019-11-28 21:23:50
If you run an entity framework migration (either automatic or explicit) against tables published for SQL Server replication you get the following error: You can only specify the READPAST lock in the READ COMMITTED or REPEATABLE READ isolation levels There have been questions about this before ( here ), but they completely fail to address the underlying cause: Entity Framework migration is run at the Serializable isolation level (as clearly shown in the SQL Server profiler). Which is a safe choice for a structure-changing transaction, but it simply isn't compatible with published sql server

How to create database using code first migrations?

泪湿孤枕 提交于 2019-11-28 21:18:35
I'm having ASP.NET MVC 3 project that uses Entity Framwork 4.3 and its migrations. Now I want Entity Framework to create a database for me using migrations that I have already. When I trying to run Update-Database script it gives me the following: Update-Database -Verbose -ProjectName AssemblyWithMigrations -StartUpProjectName WebProjectAssembly No migrations configuration type was found in the assembly '/* my name of assembly */'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration). But, when I'm trying to run Enable

Change data in migration Up method - Entity Framework

心已入冬 提交于 2019-11-28 19:07:44
I have added a new property into my existing model. It's a bool property with default value true. There are existing data in this table and I would like to set one specific row's new property to false right after creating the new field, in the Up method. public override void Up() { AddColumn("dbo.RequestValidationErrors", "IsBreaking", c => c.Boolean(nullable: false)); using (Context ctx = new Context()) { var validation = ctx.RequestValidationErrorSet.FirstOrDefault(x => x.WordCode == "RequestValidationError.MoreThanOneItemFound"); if (validation != null) { validation.IsBreaking = false; ctx

Add migration with different assembly

有些话、适合烂在心里 提交于 2019-11-28 18:40:35
I am doing a project in ASP.NET CORE 1.0.0 and I am using EntityFrameworkCore. I have separate assemblies and my project structure looks like this: ProjectSolution -src -1 Domain -Project.Data -2 Api -Project.Api In my Project.Api is the Startup class public void ConfigureServices(IServiceCollection services) { services.AddDbContext<ProjectDbContext>(); services.AddIdentity<IdentityUser, IdentityRole>() .AddEntityFrameworkStores<ProjectDbContext>() .AddDefaultTokenProviders(); } The DbContext is in my Project.Data project public class ProjectDbContext : IdentityDbContext<IdentityUser> { public