Using Redgates Sql Compare for Complex Migrations with EF’s CodeFirst

Introduction As many of you know, I’ve been quite the fan of Entity Framework CodeFirst for quite some time.  It does a great job of reducing the number of places I have to change thngs each time I have a database schema change and also brings a ton of type safety along with it.  I’ve posted before about the benefits of the auto migrations features built into CodeFirst, however I have found when I make a lot of changes to my schema, I quickly get an error saying I will have data loss so the CodeFirst Migration will not take place. In my realities, it is just too much time to go through with LINQ and try and make the perfect data migration.  My reality is that I likely only have one or two databases that need sql updates and … Continue Reading

Entity Framework Code First From Microsoft, Best and Worst Practices

  Introduction I’ve been building a fairly sophisticated product that will need to sustain a high transaction rate using the shipping version of Microsoft’s Entity Framework CodeFirst (4.1) which is part of Visual Studio.  I keep meaning to blog my experiences because I’ve been learning a huge amount about how to use and how to abuse the product.  My general style for building database intensive apps is not to spend a lot of time on optimization while I’m implementing, but to then go back and fix bottlenecks.  Back in the old days (last year), I would pretty much write my own views and then reference the with LINQ2SQL which pretty much solved most of my performance issues.  The reason is because views would allow … Continue Reading

Gaining Some Control Back From Microsoft’s Entity Framework Code First, Name Your Own Foreign Keys!

Being a relative newbie to Microsoft’s Entity Framework Code First, there are things that I don’t like, things that I don’t understand, and well, just things that really bug me.  The problem is I often find out that the things that I don’t like and bug me are often lack of knowledge and not lack of product (at least not easily discoverable in the product).  One of those things is that Code First makes up names for foreign keys that don’t happen to be the same name as I would use.  Since there are times when you will need to look at these names (and possibly code with them (for another post)), I would like those names to be my names. Let’s say you have a simple relationship between two tables.  Let’s call it User and … Continue Reading

Entity Framework CodeFirst Important Tip For SQL Execution Efficiency

  Introduction   I’ve now been using Microsoft’s Entity Framework CodeFirst for a month or two and am very impressed with how easily it is to access data in a type safe way.  I also have noticed that I need to be extra careful about how I form my LINQ or I can accidentally cause the Sql Server to do tons of extra work (tons meaning lots, not actually tons). I’ll basically explain this with actual code snippets to demonstrate my point and help you understand what I’m talking about. Let’s say you have a set of classes representing your model that basically have a master record and an associated detail record that contains an reference to a table that hold images.  That is, basically, something like this:   … Continue Reading


Get every new post delivered to your Inbox

Join other followers: