Seed Entity Framework Code First With JSON Using C# Dynamic

If you just want the short version, go to the this GitHub Repository and you’ll find a very simple project that I’ll explain in more detail here. Below are the steps necessary to achieve converting JSON into Entity Framework Seeded data. Copy the JSON file into your Visual Studio project and make the build action (file property in VS) Embedded Resource. Next, find out the name of the embedded resource. If you just don’t know it or don’t want to spend time disassembling the project you can use the GetManifestResourceNames() method as shown below.  I find that is quicker and I don’t typically have those tools loaded when I need or want then. Once we have the manifest name, … Continue Reading

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


Get every new post delivered to your Inbox

Join other followers: