entity-framework-migrations

Migrate Entity Framework 4.0 to Core

久未见 提交于 2021-02-11 13:00:27
问题 I have an old project developed with the Entity Framwork 4.0 which uses some complex types. Since I need to migrate it to .NET Core, I created a new project, installed all required libraries and used the command PM> Scaffold-DbContext "Server=ServerInstance; Database=DBName; Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models on the existing database in order to create the new models. The problem is that it does not generate the complex type classes. I can

EF Core always create .Annotation(“SqlServer:Identity”, “1, 1”) on add-migration

主宰稳场 提交于 2021-02-11 06:16:33
问题 I'm having a problem with Migration EF Core. To make the scenario clear, I'm assigning it to an existing database, which is intended to use migration for database control from now on. But I am having difficulties. What I have done so far. I generated the scaffolding from the existing database. I added the migration, so it generated all the "Up" for database creation. In a clean database, ran update-database. So far perfect, everything worked as expected. But from this step every time I

EF Core always create .Annotation(“SqlServer:Identity”, “1, 1”) on add-migration

不打扰是莪最后的温柔 提交于 2021-02-11 06:10:20
问题 I'm having a problem with Migration EF Core. To make the scenario clear, I'm assigning it to an existing database, which is intended to use migration for database control from now on. But I am having difficulties. What I have done so far. I generated the scaffolding from the existing database. I added the migration, so it generated all the "Up" for database creation. In a clean database, ran update-database. So far perfect, everything worked as expected. But from this step every time I

Can MSI work with EF CodeFirst?

安稳与你 提交于 2021-02-07 19:39:46
问题 I've gotten stuck on this for quite a while now, with no luck advancing it on my own. I am trying to connect from an Azure App Service to a EF CodeFirst managed database, using an MSI token. When I deployed the App Service using ARM I produced an Output that ensured that it created a Service Principal: { "principalId":"98f2c1f2-0a86-4ff1-92db-d43ec0edxxxx"," tenantId":"e6d2d4cc-b762-486e-8894-4f5f440dxxxx", "type":"SystemAssigned" } In Kudu the environment variables show that it is being

EF Code First Update Database Encountered Error “There is already an object named 'Products' in the database”

南笙酒味 提交于 2021-02-07 10:30:17
问题 I'm using EF5 Code First in MVC4. There are tables where fields have decimal datatypes. I just wanted to update the precision of decimal originally from (18,2) to (18,4) . Please help. To achieve the goal I just modified the OnModelCreating something like this: protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<DealerLevelDiscount>().Property(d =>d.Discount ).HasPrecision(18, 4); modelBuilder.Entity<DealerTransaction>().Property(d => d.ProductDiscount)

Can I inject dependency into migration (using EF-Core code-first migrations)?

强颜欢笑 提交于 2021-02-07 05:12:13
问题 I tried to inject IConfiguration into the migration (in constructor), and got exception: "No parameterless constructor defined for this object." any workaround? 回答1: you cannot, the migrations need to be able to run outside the context of your application. Since the Entity-framework command-line tool analyzes your code but does not run the startup.cs class. Also it is not advisable. your migrations should be plain simple and not depend on anything. if it would, it could lead to major runtime

Can I inject dependency into migration (using EF-Core code-first migrations)?

偶尔善良 提交于 2021-02-07 05:06:43
问题 I tried to inject IConfiguration into the migration (in constructor), and got exception: "No parameterless constructor defined for this object." any workaround? 回答1: you cannot, the migrations need to be able to run outside the context of your application. Since the Entity-framework command-line tool analyzes your code but does not run the startup.cs class. Also it is not advisable. your migrations should be plain simple and not depend on anything. if it would, it could lead to major runtime

Usage of Update-Database in EF Migrations when deployed in Azure

大兔子大兔子 提交于 2021-01-27 05:42:34
问题 Context: I have my ASP.NET MVC4 solution deployed in Azure. My MSSQL Server Database is also there, in Azure. I currently deploy this way: In web.config I change the connection string from local database (sdf) to azure database ( connectionString="Server=tcp:.....database.windows.net, ..." ) Right click on project name (visual studio), and then "Publish" So, my question is : How do I use the Update-database command in the Package Manager Console? Is it this way? Same step #1 from above Run

EF6 codefirst + MySql migrations: type nvarchar(max) not supported

人走茶凉 提交于 2021-01-27 04:01:52
问题 I'm trying to use EF6 code first + MySql with migrations, but I'm stuck with this error during add-migration : The underlying provider does not support the type 'nvarchar(max)' It thus seems EF is trying to use SQLServer types for MySql, even if I have changed the default connection factory in my config. I can find a lot of issues with the same error message but none of them seems up to date or to suggest something I did not already try. Here are my steps for enabling migrations in a DAL dll

EF6 codefirst + MySql migrations: type nvarchar(max) not supported

时光怂恿深爱的人放手 提交于 2021-01-27 04:01:04
问题 I'm trying to use EF6 code first + MySql with migrations, but I'm stuck with this error during add-migration : The underlying provider does not support the type 'nvarchar(max)' It thus seems EF is trying to use SQLServer types for MySql, even if I have changed the default connection factory in my config. I can find a lot of issues with the same error message but none of them seems up to date or to suggest something I did not already try. Here are my steps for enabling migrations in a DAL dll