Tuesday, January 22, 2013

Entity Framework.

Before I get going on heavy coding for the day, I wanted to post some comments on a debacle I had a bit ago.  I kept the link, and it was a really annoying situation.

I was wanting Code First Entity Framework to be implemented in my project, and for a bit, I worked on it manually.  Then I found some Nuget packages for Entity Framework that reverse engineer your dbcontext from an existing database.  I was in Visual Studio 2012, and I couldn't get the darn thing to work.  Kept telling me that it couldn't find T4VSHost, so I went on a google trip.   Found this link and the workaround.

Entity Framework Error.

I went to this location :

C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\EF.Utility.CS.ttinclude (for C#)

Deleted this line.

<#@ CleanupBehavior Processor="T4VSHost" CleanupAfterProcessingTemplate="true" #>

That was pretty much the end of my EntityFramework problems for what I was trying to get to happen.  Since then, I've been using AutoMapper, and the custom converters, or just selecting into new types with my lambda's.

AutoMapper Converters

Entity Framework allows a lot more flexibility than Linq to SQL, but it comes with additional overhead, and more "rules".   I love Code First, gives me a lot more control, without losing any of my customization.