ef-migrations

Adding a migrations gives filename already exists

微笑、不失礼 提交于 2019-12-23 12:39:15
问题 I have enabled migrations as such: enable-Migrations -ProjectName ProjectOne -ContextTypeName MyIdentity.Config.MyIdentityContext -MigrationsDirectory Identity\\Migrations I specified my context as it is in a separated namespace, and i specified the directory because i want to have the migrations in a different directory. After enabling the migrations like this, i get the expected configuration file in the expected location (Identity\Migrations folder) (i removed the comments in the seed

Database applies ALL previous migrations on update and NOT just the new one

烂漫一生 提交于 2019-12-23 09:47:01
问题 I'm developing a website which, as of current, both has a production and a test database. The production database is hosted externally while the test database is hosted locally. Whenever I make changes to my database I apply the changes through a migration. After having added a new migration I run the update-database command on both my production and test database to keep them in sync. I applied the migration just fine to my production database, however, when I wanna apply the migration to my

Database applies ALL previous migrations on update and NOT just the new one

安稳与你 提交于 2019-12-23 09:46:25
问题 I'm developing a website which, as of current, both has a production and a test database. The production database is hosted externally while the test database is hosted locally. Whenever I make changes to my database I apply the changes through a migration. After having added a new migration I run the update-database command on both my production and test database to keep them in sync. I applied the migration just fine to my production database, however, when I wanna apply the migration to my

EF Migrations DropForeignKey fails when key is in a base class

坚强是说给别人听的谎言 提交于 2019-12-23 09:34:34
问题 I'm attempting to update my data models for an EF 5.0.0-rc code-first class library. The first command in the Up() method is DropForeignKey("dbo.ChileInventory", new[] { "LotInventoryItemTypeId", "ChileProductId" }, "dbo.ChileProducts"); but I'm getting a SqlException: 'FK_dbo.ChileInventory_dbo.ChileProducts_LotInventoryItemTypeId_ChileProductId' is not a constraint. Could not drop constraint. I think that the cause for the error is due to the fact that my ChileProducts class get's it's key

EntityFramework anonymous composite key property name conflict

天涯浪子 提交于 2019-12-23 08:49:14
问题 I'm using EntityFramework 5 (or 4.3 for .Net Framework 4.0) In my DbContext object I have already set the correct DbSets and the objects contain proper references to each other. This is not new for me, and things are working well. Now in this case I have some composite keys that, sometimes, include the foreign key of a table (or object in this case). For this I use the HasKey<>() function on the OnModelCreating method of the DbContext. When these properties have different names, there is no

How to UPDATE DATABASE in Code First approach automatically after check-in and Publish code in Continuous deployment

会有一股神秘感。 提交于 2019-12-23 03:19:57
问题 ​In our Web API application, Continuous deployment need a following scenario. User will check in code in VS, Code will get automatically build, Code will be Published, Code will be deployed. But If we are using Entity Framework Code First approach, How can we update database without manual commands (Add-Migration/Update Database)and make database up to date with that check-in. 回答1: You can try to run Add-Migration/Update Database commands in the build/deploy process. Assume you are using

How do I get Entity Framework 4.3 Code First to map a subclass using Table Per Type (TPT)?

▼魔方 西西 提交于 2019-12-23 02:57:06
问题 I'm using EF 4.3 Code First and automatic migrations. I have the following 3 classes: public class BaseUser { [Key] [MaxLength(50)] public string Username { get; set; } [MaxLength(200)] public string Password { get; set; } } public class AdminUser : BaseUser { public int SettingsFlag { get; set; } } public class RegularUser : BaseUser { public DateTime LastLogin { get; set; } public DateTime LastSummary { get; set; } [MaxLength(100)] public string Email { get; set; } public int CompanyID {

Web Api 2.2 - Code First Migration in Class Library Project

喜欢而已 提交于 2019-12-23 02:41:22
问题 I have two projects in myVS 2015 solution. Project A Web Api 2.2 Project Main Project where DBContext class and connection string (in web.config file) is defined Project B Class Library Project Project A added as a reference Models & Controller Defined Models inherits a class of Project A Created a DBContext class which inherits DBContext from Project A. public DbSet Planets { get; set; } My idea behind the above project structure is: To reduce the complexity when project grows larger To make

EF Code first 4.3 naming convention foreign key

谁说胖子不能爱 提交于 2019-12-22 18:26:15
问题 I have the following entity: public class User { public int ID {get; set;} public int GroupID {get; set;} // navigation property with public Group Group {get; set;} // foreign key field public Adress Adress {get; set;} // navigation property only } The table generated from entity framework looks like: ID GroupID Adress_ID I don't like, that the column naming for the FK columns is not the same. Can I achieve that both use the same convention either "GroupID, AdressID" or "Group_ID, Adress_ID"?

How to use EF6 with ASP.NET Core 1

烂漫一生 提交于 2019-12-22 08:23:26
问题 I created an ASP.NET Core 1 project and using .Net Core 1.0 framework. And want to use the Entity Framework 6 . I follow this tutorials https://docs.efproject.net/en/latest/platforms/aspnetcore/new-db.html and when I try to migrate with the statement: PM> Add-Migration MyFirstMigration then it shows me: The EntityFramework package is not installed on project 'IndustryCloud'. It is possible to use EF6 with ASP.NET Core 1? 回答1: You can use Entity Framework 6 with ASP.Net Core 1.0. An example