ef-migrations

Downgrade (Rollback) Database with code-first in production environment

孤人 提交于 2020-01-13 08:04:03
问题 I have a web application that I install on my customers' computers for their inner use. I use C# MVC5 and code-first Entity Framework. I used automatic migration=true but I stopped and set it to false. I installed it on a production environment (release) - with a deploy-package (no Visual Studio). I have a customer with the application - version 1. Now I want to upgrade to version 2. I want to enable to upgrade the App's DB (in production file, with CMD installation from a package), but to

Keyword not supported error in Enabling migrations

荒凉一梦 提交于 2020-01-13 07:01:09
问题 I have a dbcontext class where i have initialized 4 dbsets. My connection string is <connectionStrings> <add name="somename" connectionString="Data Source=.; initial catalog=someDb; user ID=ab; Password:111111; MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" /> </connectionStrings> My dbcotext class is public AstroEntities(): base("somename") { Database.SetInitializer<AstroEntities>(new CreateDatabaseIfNotExists<AstroEntities>()); } protected override void OnModelCreating

Schema Migration Scripts in NoSQL Databases

五迷三道 提交于 2020-01-12 03:26:50
问题 I have a active project that has always used C#, Entity Framework, and SQL Server. However, with the feasibility of NoSQL alternatives daily increasing, I am researching all the implications of switching the project to use MongoDB. It is obvious that the major transition hurdles would be due to being "schema-less". A good summary of what that implies for languages like C# is found here in the official MongoDB documentation. Here are the most helpful relevant paragraphs (bold added): Just

How to drop a table in Entity Framework Code First?

 ̄綄美尐妖づ 提交于 2020-01-11 08:22:28
问题 I am using Entity Framework with Auto Migrations. So when I add a new model to my Context, my database is updated and new table is created. What I want to do is the opposite, droping the table completely from database. However, removing the definition from Context class does not work. public class CompanyContext : DbContext { public DbSet<Permission> Permissions { get; set; } public DbSet<Company> Companies { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) {

How can I set the foreign key name using the Fluent API with Code First Migrations?

爱⌒轻易说出口 提交于 2020-01-11 08:01:12
问题 I'm trying to set the foreign key name (not the foreign key column) using Code First Migrations on EF6.4. I know that it can be set by updating the generated migration code, like so: .ForeignKey("Documents", Function(t) t.DocumentId, cascadeDelete:=True, name:="FK_Sections_Documents") ...but I'd like to do it before the migration is added, using the Fluent API. I seem to recall something about the HasForeignKey() call accepting a Func that contains a call to an anonymous type in its body,

Entity Framework Code First Migrations failing on Wrong Provider (3.5 instead of 4.0)

大城市里の小女人 提交于 2020-01-11 07:23:06
问题 I am trying to add a migration (for the first time) to a project using Entity Framework 6.0.2 for SQL Server Compact (code first). The application is having no problems communicating with the database. The migration is failing with the error message: System.InvalidOperationException: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlServerCe.3.5'. Make sure the provider is registered in the 'entityFramework' section of the application config file.

EFCore Not recognizing Database Provider

僤鯓⒐⒋嵵緔 提交于 2020-01-10 05:25:05
问题 I have a .Net Core WebApplication Project in which the Context Class is in a Class Library. If I hard code the connection string in the OnConfiguring(DbContextOptionsBuilder optionsBuilder) method I can generate migrations. Since it is better to let dependency injection manage the context I would like to add this to the Startup Class. However when I do I get the following error: No database provider has been configured for this DbContext. A provider can be configured by overriding the

How to make persisted computed column in EF code first?

瘦欲@ 提交于 2020-01-10 02:52:08
问题 How do I get this column as similar to a PERSISTED COMPUTED column in the database? My current attempt (it loads all CompCol rows with null in seed) : public class Call { public Call() { } [Key] public int Id { get; set; } [DatabaseGenerated(DatabaseGeneratedOption.Computed)] public string CompCol { get { return "ABC-" + Convert.ToString(Id).PadLeft(5, '0'); } protected set {} } } 回答1: The solution I found was to : Make sure auto migrations are turned off. This is so that VS will generate a

Is adding a class that inherits from something a violation of the solid principles if it changes the behavior of code?

£可爱£侵袭症+ 提交于 2020-01-09 07:40:26
问题 I struggled to enable my code to run code first EF migrations using different connection strings, and finally got it working. The method I used is outlined in my answer to this question What bothers me is that in order to be able to run the same code using different connection strings I had to 1) Resort to a global setting to store the connection string 2) Introduce a class whose very presence caused the code to behave differently. This is so different to the way I am used to working. Is the

Entity Framework Auto Migrations Primary Key

♀尐吖头ヾ 提交于 2020-01-07 04:55:13
问题 I have inherited a sql server database and an ASP.Net MVC 4 web application which is using Entity Framework 5.0 Code First with Auto Migrations . However, it appears the previous developer forgot to add a Primary Key to one of the tables. I am now trying to do this using Auto Migrations , however, it is not working, no errors either, just seems to be ignoring the command. The table is like this public int CourseDateHistoryID { get; set; } public int CourseDateID { get; set; } public int Event