entity-framework-4.3

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

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

霸气de小男生 提交于 2019-11-27 09:11:24
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 HomeController : Controller { protected EFDbContext Db = new EFDbContext(); public ActionResult Index() { Blog B =

How to disable migration in Entity Framework 4.3.1?

▼魔方 西西 提交于 2019-11-27 08:13:13
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? Ladislav Mrnka 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>()); Noel Deleting the Migrations folder has worked for me. I don't get any errors, it puts me back to where I started. Buzzrick The way

Entity framework 4.3 run migrations at application start

限于喜欢 提交于 2019-11-27 07:34:45
What is the best way to execute all required db migrations at application start with EF 4.3? The best way should be using new MigrateDatabaseToLatestVersion initializer. Database.SetInitializer<YourContext>( new MigrateDatabaseToLatestVersion<YourContext, YourMigrationsConfig>()); Database.Initialize(false); 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 Initializers, including the new Code First MigrateDatabaseToLatestVersion initializer. Although Entity Framework

How to create initializer to create and migrate mysql database?

半腔热情 提交于 2019-11-27 07:19:33
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.ExecuteSqlCommand("CREATE UNIQUE INDEX Name ON Stations (Name)"); // Other stuff } } Or I can create a

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

点点圈 提交于 2019-11-27 06:55:25
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 extension after table creation in the migration Up method. But is there an elegant built in way that I've yet

Introducing FOREIGN KEY constraint on table may cause cycles or multiple cascade paths causing Database.SetInitializer to not work?

試著忘記壹切 提交于 2019-11-27 06:19:40
问题 My code-first database was working great. If I made a change to my database context the database would be updated the next time I started the application. But then I added some models to the database and got this error when I restarted my application: Introducing FOREIGN KEY constraint 'FK_OrderDetails_Orders_OrderId' on table 'OrderDetails' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Could not create

Is it possible to express a check constraint?

我是研究僧i 提交于 2019-11-27 06:07:57
问题 I'm doing code-first development with Entity Framework 4.3 and it doesn't seem like it's possible to express a CHECK constraint via attribute annotations or, well, any other means. I see that EF 5.0 will be adding support for checking enumerations, but that's not exactly what I'm after here. To give a simplified example, I'd like to validate that all Person objects have a first name of either "Bob" or "Harry" and are either 5, 10 or 30 years old. public class Person { [Required] [Check("Bob",

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

蓝咒 提交于 2019-11-27 04:57:11
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 has an effect. How can I have an EF 4.3 context talk to an EF 4.3-generated database built by a different

EF 4.3.1 Migration Exception - AlterColumn defaultValueSql creates same default constraint name for different tables

蓝咒 提交于 2019-11-27 04:43:30
问题 I have a DB that I created using the OOB database initializer, and I am using Code First with EF 4.3.1. I wanted to take advantage of the new "IgnoreChanges" flag on the Add-Migration cmdlet, so that I can alter some of my columns and add a default SQL value. Essentially, some of my entities have a column named DateLastUpdated, which I would like to set the DEFAULT to the sql expression GETDATE(). I created the InitialMigration using "add-migration InitialMigration -ignorechanges", and then I