Using IntelliTrace With Entity Framework In Visual Studio 2012


This is not a big deal, but I have recently bumped into several people that did not know about it so I thought I’d do a blog post just to show what it is and how is just trivial to use for useful stuff. The issue I’m showing is how to see the Sql generated from Entity Framework.  My old habit use to be to stop the debugger and hover over the query variable in the code, grab it as a debug variable, then cut and paste to SqlServer enterprise. Now, I just go to the DEBUG menu in VS, Windows / Intellitrace and I get a nice listing on the right side of all my ADO.NET calls.  The last one is the one I just did.  My code below is pretty self explanatory.  You can see I’ve just issued a db.SaveChanges().  You can also … Continue Reading

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

Extending CodeFirst (EntityFramework) to Multiple Levels of 1 to 1 Relationships (Strongly Typed)


In my previous post, I showed how to take a simple relationship between Customers and an one Detail per customer build that into a relationship that eagerly loaded the customer record when retrieving a Detail record with CodeFirst in EntityFramework.  Now, let’s extend that so that a customer has an Address associated with them. This means, the relationship is as follows: Detail     Customer         Address Or, using my favorite Sql Manager Tool from EMS Database Management Solutions:     The model is now as follows: namespace Con1 { public class SiteDB : DbContext { public DbSet<Detail> Details { get; set; } … Continue Reading


Get every new post delivered to your Inbox

Join other followers: