ef-migrations

Best way to incrementally seed data in Entity Framework 4.3

和自甴很熟 提交于 2019-11-27 11:33:39
I have been using Entity Framework 4.3 on an existing database and I have a couple of scenarios that I am trying to cater for. Firstly, if I delete my database I would like to EF to recreate if from scratch - I have successfully used a CreateDatabaseIfNotExists database initialiser for this. Secondly, if I update my model and the database already exists I would like the database to be updated automatically - I have successfully used Entity Framework 4.3 Migrations for this. So here's my question. Say I add a new table to my model which requires some reference data, what it the best way to

Code First Migration with Connection Strings

丶灬走出姿态 提交于 2019-11-27 11:30:15
问题 So I've managed to get Code First running and it works great. Since I am still developing the application the structure of the Database isn't finalize and so I need to implement migrations. I followed the Official Blog Post and got that Update-Database command working. However, this only updates the SQLExpress version of the database. The production version of the database is on Azure and I specify the connection string at run time so the Update-Database command doesn't work on that. So my

Add migration with different assembly

徘徊边缘 提交于 2019-11-27 11:07:52
问题 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

Entity Framework, Automatic apply Migrations

折月煮酒 提交于 2019-11-27 10:58:48
问题 I am using Entity Framework Code First approach with AutomaticMigrationsEnabled = true : Database.SetInitializer(new MigrateDatabaseToLatestVersion<DbContext, MigrateDBConfiguration>()); ////////////////////////////////// public class MigrateDBConfiguration : System.Data.Entity.Migrations.DbMigrationsConfiguration<DbContext> { public MigrateDBConfiguration() { AutomaticMigrationsEnabled = true; AutomaticMigrationDataLossAllowed = true; } } The first run of the project creates the database and

Adding CreatedDate to an entity using Entity Framework 5 Code First

筅森魡賤 提交于 2019-11-27 10:31:28
问题 I am trying to add a CreatedDate property to entities in my Model and am using EF5 Code First. I want this date to not be changed once set, I want it to be a UTC date. I do NOT want to use a constructor, as I have many entities in my model that I want to inherit from an abstract class containing the CreatedDate property, and I can't enforce a constructor with an interface. I have tried different data annotations and I have attempted to write a database initializer that would pick up a

Automatic Migrations for ASP.NET SimpleMembershipProvider

点点圈 提交于 2019-11-27 10:14:48
So I tried to use automatic migrations with my new MVC 4 Project but somehow it isn't working. I followed this blog post step by step. I've added the changes to the UserProfile account model (the NotaryCode field): [Table("UserProfile")] public class UserProfile { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int UserId { get; set; } public string UserName { get; set; } public int NotaryCode { get; set; } } Then I wrote on the package manager console enable-migrations and a Configuration class appeared (inherits from DbMigrationsConfiguration<Web.Models

Generate full SQL script from EF 5 Code First Migrations

走远了吗. 提交于 2019-11-27 10:01:31
How do I use Entity Framework 5 Code First Migrations to create a full database script from the initial (empty) state to the latest migration? The blog post at MSDN Blog suggests to do this, but it seems to create an empty script: Update-Database -Script -SourceMigration: $InitialDatabase The API appears to have changed (or at least, it doesn't work for me). Running the following in the Package Manager Console works as expected: Update-Database -Script -SourceMigration:0 Tahir Khalid To add to Matt wilson's answer I had a bunch of code-first entity classes but no database as I hadn't taken a

The term 'Update-Database' is not recognized as the name of a cmdlet

我是研究僧i 提交于 2019-11-27 09:54:18
问题 I am using EF5 beta1 and while I was able to run the "Update-Database" before. Now that I shut down Visual Studio, I cannot get it to run. I get the following error: The term 'Update-Database' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:16 + Update-Database <<<< -verbose + CategoryInfo : ObjectNotFound: (Update-Database:String) [],

How to explicitly name the database when using Entity Framework Migrations 4.3

会有一股神秘感。 提交于 2019-11-27 09:44:15
问题 I've recently started using Entity Framework migrations and noticed that the database name is not pulling through for me when I run the Update-Database command. My connectionstring is: <connectionStrings> <add name="DataContext" connectionString="Server=.\SQLEXPRESS;Initial Catalog=TestDB;Trusted_Connection=Yes;" providerName="System.Data.SqlClient" /> </connectionStrings> The very first time I run Update-Database my database is created with the correct name TestDB . However, as soon as I

Oracle.ManagedDataAccess.EntityFramework - ORA-01918: user 'dbo' does not exist

痞子三分冷 提交于 2019-11-27 09:12:43
I am trying to implemente code First Migrations with Oracle.ManagedDataAccess 6.121.1.0 provider, but with no success at all. As I am receiving a ORA-code, I am assuming that the connection are been opened successfully. But the Migrations are failing because, maybe, the provider are behaving as a SQL Server, instead of Oracle. I think that beacause it is traying to use 'dbo' as default schema. Here is my web.config settings: <configuration> <configSections> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0,