Code First has automatic functionality built in to help you get up and running with a database and warn you when you may have made a mistake that will cause your app to fail. This is generally helpful when you are developing an application – especially when you are new to EF – but when … Continue reading Reducing Code First Database Chatter
Migrations
EF6: Switching Identity On/Off with a Custom Migration Operation
Here is the scenario, I have a class in my Code First model that has a primary key configured as an identity column. I want to change it so that I can generate values in my code. Alternatively I may want to change an existing column - that my code is generating values for - … Continue reading EF6: Switching Identity On/Off with a Custom Migration Operation
EF6: Writing Your Own Code First Migration Operations
Migrations provides a set of strongly typed APIs for performing common operation, for example CreateIndex("dbo.Blogs", "Url"). We also provide a method that allows you to run arbitrary SQL when you want to do something that isn’t supported by the API, for example Sql("GRANT SELECT ON dbo.Blogs to guest"). There are some disadvantages to the Sql … Continue reading EF6: Writing Your Own Code First Migration Operations
Code First Migrations – Customizing Scaffolded Code
A while back I blogged about customizing the SQL that is generated by Code First Migrations. In this post I’m going to step back up the pipeline a bit and look at customizing the code that gets scaffolded when you call Add-Migration. When we built Code First Migrations we made an effort to make everything … Continue reading Code First Migrations – Customizing Scaffolded Code
//build/ 2012 Talk Video and Source Code
This year at the //build/ conference I presented a session titled ‘Building data centric applications for web, desktop and mobile using EF5’. In addition to EF5, I also covered the what and when of EF6 and did a quick demo of my favorite EF6 feature (custom code first conventions). You can view the session recording, … Continue reading //build/ 2012 Talk Video and Source Code
Dynamically Building a Model with Code First
I’ve answered a few emails recently on this topic so it felt like time to turn it into a blog post. In this scenario the set of classes that make up your model isn’t known at compile time and is discovered dynamically at runtime. An example of such a scenario is a WordPress/Orchard/etc. style website … Continue reading Dynamically Building a Model with Code First
Running & Scripting Migrations from Code
Code First Migrations is included as part of Entity Framework starting with the EF 4.3 release. Migrations are normally created and run from the Package Manager Console in Visual Studio. These commands are just thin wrappers over public APIs that you can call directly from your own code. In this post you’ll see how to … Continue reading Running & Scripting Migrations from Code
Customizing Code First Migrations Provider
Code First Migrations is included as part of Entity Framework starting with the EF 4.3 release. One feature we haven’t really blogged about yet is the ability to include additional arguments in a migration operation. These arguments are then made available to the SQL generator. You can then derive from the SQL generators that we … Continue reading Customizing Code First Migrations Provider
Magic Free Code First Migrations
This post is now out of date. Be sure to check out EF 4.3 Beta 1. <transparency>I work for Microsoft</transparency> (just kidding… but I couldn’t leave the tag open) We recently released a very early preview of Code First Migrations and it’s been getting some mixed feedback, the negative feedback falls into three buckets: Stuff … Continue reading Magic Free Code First Migrations