entity-framework-4.3

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

China☆狼群 提交于 2019-11-26 19:02:56
问题 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

Best way to incrementally seed data in Entity Framework 4.3

大憨熊 提交于 2019-11-26 15:37:42
问题 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

Can anyone spot why I keep getting this error testing the EF 5 beta

有些话、适合烂在心里 提交于 2019-11-26 14:36:27
问题 Installed visual studio 11 beta as wanted to test EF 5 beta but keep hitting this an error. Method not found: 'Void System.Data.Objects.ObjectContextOptions.set_UseConsistentNullReferenceBehavior(Boolean)'. Project is a new blank MVC3 application and below is some code that illustrate how the error happens. public class Blog { public int Id { get; set; } public string Name { get; set; } } public class EFDbContext : DbContext { public DbSet<Blog> Blogs { get; set; } } public class

How to disable migration in Entity Framework 4.3.1?

谁都会走 提交于 2019-11-26 13:56:14
问题 Is there any way to disable migration in Entity Framework 4.3.1? I removed the migrations folder from the project and the generated tables in my database, but it doesn't work! How can you remove the migration? 回答1: If you don't want to use migrations but in the same time you want EF to create database for you, you just need to set correct database initializer: Database.SetInitializer<YourContextType>(new CreateDatabaseIfNotExists<YourContentType>()); 回答2: Deleting the Migrations folder has

Entity framework 4.3 run migrations at application start

帅比萌擦擦* 提交于 2019-11-26 13:48:55
问题 What is the best way to execute all required db migrations at application start with EF 4.3? 回答1: The best way should be using new MigrateDatabaseToLatestVersion initializer. Database.SetInitializer<YourContext>( new MigrateDatabaseToLatestVersion<YourContext, YourMigrationsConfig>()); Database.Initialize(false); 回答2: A great description of the EF 4.3 configuration options can be found at EF 4.3 Configuration File Settings on the ADO.NET team blog. The very last section describes Database

How to create initializer to create and migrate mysql database?

我与影子孤独终老i 提交于 2019-11-26 13:08:30
问题 I have been learning how to use EF for a week or so now and am stuck on the issue of creating/updating my database. I am able to create an initializer to create the database if it is not there: static class Program { static void Main() { Database.SetInitializer<GumpDatabase>(new GumpDatabaseInitializer()); .... class GumpDatabaseInitializer : CreateDatabaseIfNotExists<GumpDatabase> { public GumpDatabaseInitializer() { } protected override void Seed(GumpDatabase context) { context.Database

How can I disable model compatibility checking in Entity Framework 4.3?

妖精的绣舞 提交于 2019-11-26 12:46:37
问题 I\'m working with EF 4.3 and have a context which needs to talk to a database which was generated by another library using EF Code First 4.3. The context is throwing an exception stating The model backing the \'Context\' context has changed since the database was created. Consider using Code First Migrations to update the database In EF 4.1 this could be diabled by removing the IncludeMetadataConvention from the ModelBuilder. However, in 4.3 this convention has been deprecated and no longer

How to add description to columns in Entity Framework 4.3 code first using migrations?

不想你离开。 提交于 2019-11-26 12:11:50
问题 I\'m using Entity Framework 4.3.1 code first with explicit migrations. How do I add descriptions for columns either in the entity configuration classes or the migrations, so that it ends up as the description of a column in SQL server (e.g. 2008 R2)? I know I can probably write an extension method for the DbMigration class that would register the sp_updateextendedproperty or sp_addextendedproperty procedure call as a sql migration operation inside the migration transaction and call that

What difference does .AsNoTracking() make?

馋奶兔 提交于 2019-11-26 11:32:15
I have a question regarding the .AsNoTracking() extension, as this is all quite new and quite confusing. I'm using a per-request context for a website. A lot of my entities don't change so don't need to be tracked, but I have the following scenario where I'm unsure of what's going to the database, or even whether it makes a difference in this case. This example is what I'm currently doing: context.Set<User>().AsNoTracking() // Step 1) Get user context.Set<User>() // Step 2) Update user This is the same as above but removing the .AsNoTracking() from Step 1: context.Set<User>(); // Step 1) Get

Entity Framework initialization is SLOW — what can I do to bootstrap it faster?

一世执手 提交于 2019-11-26 10:35:10
问题 My EF 4.3.1 model has 200-odd tables. Initial startup is horrible, several minutes. A DotTrace-captured profile implies some terrible algorithm/scalability choices deep in the framework, as evidenced by the millions of calls to a number of methods down there and the 36 million IEnumerable.Contains() calls. Here is a snippet, this is all triggered by the first query done on the database (future queries don\'t do this and are fine). What can I do to my model to make this less painful? Can I