One of the most popular posts on my blog has been EF6.1 Mapping Between Types & Tables. Someone asked me this week about getting the property/column mapping in addition to the type/table mapping. There isn’t a whole lot to say (other than the code is horrible and this will look a whole lot better in … Continue reading EF6.1 Get Mapping Between Properties and Columns
Visual Studio
Reducing Code First Database Chatter
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
EF6/6.1 Level 300-400 Talk-in-a-Box
I recently posted an EF6 Level 100-200 Talk-in-a-Box to make it easier for folks to present EF6 to their user group, local conference, work colleagues, or anyone who would listen. I also recently put together a more in-depth talk on EF for Building Modern Web Apps day of Azure Week. I just tidied up the … Continue reading EF6/6.1 Level 300-400 Talk-in-a-Box
EF6 Level 100-200 Talk-in-a-Box
Putting a good technical talk together takes a decent amount of work. You need to make sure your talk tells a story from end-to-end, you need to give folks enough context (without spending the whole talk in PowerPoint), and you need clear concise demos that folks can follow. You also have to make sure your … Continue reading EF6 Level 100-200 Talk-in-a-Box
EF Code First Mapping Between Types & Tables
Starting in EF6.1 there is an easier way to do this. See my new EF6.1 Mapping Between Types & Tables post for details. Entity Framework includes the MetadataWorkspace which gives you access to the metadata EF keeps about the shape of your model. The problem is that the Mapping section of this – the bit … Continue reading EF Code First Mapping Between Types & Tables
EF5 & EF6 on VS Toolbox (Source Code Included)
I recently had the pleasure of appearing on a Visual Studio Toolbox episode, hosted by Robert Green, with my co-worker Glenn Condron. Back in the EF4.3 days I had been part of another 2 part series on VS Toolbox with Diego Vega. Since the previous episodes were so popular we thought we should catch up … Continue reading EF5 & EF6 on VS Toolbox (Source Code Included)
EF6 Suspendable Execution Strategy
EF6 introduces the new connection resiliency feature that allows for automatic retries of failed database operations. I was recently writing some documentation for EF6 and came across a scenario where it would be useful to have a global switch to enable/disable retry logic. Such a switch isn’t built into EF6, although we do have an … Continue reading EF6 Suspendable Execution Strategy
TechEd 2013 Talks & Source Code
Last week I had the pleasure of attending TechEd 2013 to present a couple of sessions. Here are links to the session recordings, slides and source code. Breakout Session: Entity Framework 6: Database Access Anywhere, Easily This session covers the basics of EF6, open source, and a series of demos for the new EF6 … Continue reading TechEd 2013 Talks & Source Code
How to Drop a Database from Visual Studio 2012
Seems like it should be easy right? It depends which SKU of Visual Studio you have… Option 1: SQL Server Object Explorer If you have a SKU of Visual Studio that includes SQL Server Object Explorer (SSOE) then it’s pretty easy. You’ve probably only got this if you parted with some hard earned cash … Continue reading How to Drop a Database from Visual Studio 2012
Running EF T4 Code Generation Templates from Command Line
Since EF4 and Visual Studio 2010 you have been able to use T4 templates to generate code from models created using the EF Designer. Starting with EF5 and Visual Studio 2012 T4 based code generation is the default for new models created using the EF Designer. When you create a new model using VS2012 or later … Continue reading Running EF T4 Code Generation Templates from Command Line
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
Processor named ‘T4VSHost’ could not be found for the directive named ‘CleanupBehavior’
There are two scenarios in which you may see the 'Processor named ‘T4VSHost’ could not be found for the directive named ‘CleanupBehavior’' error after installing Visual Studio 2012 Update 1. Inside Visual Studio when code is being generated from an EF model - this isn't supposed to happen and something probably went wrong during install. … Continue reading Processor named ‘T4VSHost’ could not be found for the directive named ‘CleanupBehavior’
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
Extending And Customizing Code First Models – Part 2 of 2
Here is the scenario, your company ships a library or application that contains a Code First model for accessing the database. Your customers want to extend this model to include extra types/properties to meet their specific business needs. These types/properties will be stored in additional tables/columns in the application database. In Part 1 we looked at … Continue reading Extending And Customizing Code First Models – Part 2 of 2
Extending and Customizing Code First Models – Part 1 of 2
Here is the scenario, your company ships a library or application that contains a Code First model for accessing the database. Your customers want to extend this model to include extra types/properties to meet their specific business needs. These types/properties will be stored in additional tables/columns in the application database. In this post I’ll walk … Continue reading Extending and Customizing Code First Models – Part 1 of 2
EF6 Code First: Configuring Unmapped Base Types
If your object model contains inheritance, Code First gives you two options for the base type – it can either be mapped or unmapped. A mapped base type means the inheritance hierarchy is represented in the database using either the TPH, TPT or TPC pattern. An unmapped base type means Code First effectively ignores your … Continue reading EF6 Code First: Configuring Unmapped Base Types
EF6 Code First: Mapping All Private Properties Using Custom Conventions
A while back I blogged about mapping to private properties with Code First. The approach shown in that post works with EF4.1 onwards but it requires you to explicitly configure every private property that you want included in your model. That’s going to get tiresome if you have a big model and want all private … Continue reading EF6 Code First: Mapping All Private Properties Using Custom Conventions
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
Mapping to Private Properties with Code First
By default Code First will just include public properties in your model, but there may be times that you want to include private properties. Arthur Vickers wrote a great detailed post on working with private properties so I'm just going to cover enough to get you started in this post. For example, the following model … Continue reading Mapping to Private Properties with Code First