ef-migrations

EF Migrations: Rollback last applied migration?

て烟熏妆下的殇ゞ 提交于 2019-11-28 02:31:59
This looks like a really common task, but I can't find an easy way to do it. I want to undo the last applied migration. I would have expected a simple command, like PM> Update-Database -TargetMigration:"-1" Instead, all I can come up with is: PM> Get-Migrations Retrieving migrations that have been applied to the target database. 201208012131302_Add-SystemCategory 201207311827468_CategoryIdIsLong 201207232247409_AutomaticMigration 201207211340509_AutomaticMigration 201207200025294_InitialCreate PM> Update-Database -TargetMigration:"CategoryIdIsLong" (At least I can use just the name, skipping

EF 4.3.1 Migration Exception - AlterColumn defaultValueSql creates same default constraint name for different tables

房东的猫 提交于 2019-11-28 00:15:02
I have a DB that I created using the OOB database initializer, and I am using Code First with EF 4.3.1. I wanted to take advantage of the new "IgnoreChanges" flag on the Add-Migration cmdlet, so that I can alter some of my columns and add a default SQL value. Essentially, some of my entities have a column named DateLastUpdated, which I would like to set the DEFAULT to the sql expression GETDATE(). I created the InitialMigration using "add-migration InitialMigration -ignorechanges", and then I added the following to the Up() and Down(): public override void Up() { AlterColumn("CustomerLocations

Entity Framework Code First Migrations: Set Primary Key Value

人走茶凉 提交于 2019-11-27 22:00:09
I have a table that stores some extra data for some rows of a table like: public class QuoteExtra { [Key] public int QuoteId { get; set; } // More fields here } I'd like to be able to add rows to this table where I explicitly set the PK. If I simply leave it as above, setting a value and submitting the row causes the value to be discarded and replaced with the auto-generated value from the database (and the column is defined as an Identity column in the actual schema). This appears to be the right solution: public class QuoteExtra { [Key] [DatabaseGenerated(DatabaseGeneratedOption.None)]

Create Table, Run Time using entity framework Code-First

余生长醉 提交于 2019-11-27 21:03:24
问题 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 . 回答1: Yes,you can do that. You can do that using Finding the Classes : [AttributeUsage(AttributeTargets.Class)] public class

How to create database using code first migrations?

自古美人都是妖i 提交于 2019-11-27 20:57:52
问题 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

How do I undo the last Add-Migration command?

£可爱£侵袭症+ 提交于 2019-11-27 19:51:16
问题 I have created a migration using the Add-Migration command, but I'd like to change the name of that migration. How can I undo the migration command, so that I can regenerate it using the new desired name? Is it just a matter of deleting the generated files, or this could be a bad idea? 回答1: If you haven't used Update-Database you can just delete the migration file. If you've run the update you should roll it back using Update-Database -TargetMigration "NameOfPreviousMigration" then delete the

MultiTenant Application Prevent Tenant Access Data from Other Tenant in Shared Database

一世执手 提交于 2019-11-27 18:59:24
问题 I’m working on a tenant application and i was wondering how i can block tenant access other tenant data. First, let me expose some facts: The app is not free, 100% for sure the malicious user is a client. All the primary keys/identity are integers (Guid solve this problem but we can't change right now). The app use shared database and shared schema. All the tenants are business group wich own several shops. I'm use Forgery... I have some remote data chosen by dropdown and its easy change the

Entity Framework Code First Migrations - Enable-Migrations fails

不想你离开。 提交于 2019-11-27 18:50:31
问题 I have been trying to use code-first migrations, and had some limited success, but one of the things I got wrong was that I failed to tell it which project had the config information. It generated some classes for me, and I sort-of got it all working, but I figured that I should sort out the configuration issue and start over. Bad mistake. Now that I've attempted to remove all the migrations stuff, I find I cannot re-install it. I've un-installed and re-installed EF 5, but when I use the

EF 5 Enable-Migrations : No context type was found in the assembly

馋奶兔 提交于 2019-11-27 17:57:46
I have 4 projects : Toombu.Entities : all models are there Toombu.DataAccess: Mapping, Repository and ToombuContext Toombu.Logique : Logic of my application Toombu.Web : MVC 4 application. With all others DLL. I tried to enable migration in Toombu.Web but i had this error : No context type was found in the assembly How can I enable migration ? hVostt use -ProjectName option in Package Manager Console: Enable-Migrations -ProjectName Toombu.DataAccess -StartUpProjectName Toombu.Web -Verbose I am surprised that no one mentioned the obvious answer to this question: Entity Framework requires a

Confusion over EF Auto Migrations and seeding - seeding every program start

不羁岁月 提交于 2019-11-27 17:30:49
I recently changed an application from using the following for dev: DropCreateDatabaseIfModelChanges<Context> To using: public class MyDbMigrationsConfiguration: DbMigrationsConfiguration<GrsEntities> { public MyDbMigrationsConfiguration() { AutomaticMigrationsEnabled = true; AutomaticMigrationDataLossAllowed = true; } } In my db context I have: protected override void OnModelCreating(DbModelBuilder modelBuilder) { // Tell Code First to ignore PluralizingTableName convention // If you keep this convention then the generated tables will have pluralized names. modelBuilder.Conventions.Remove