Entity Framework

  • Entity Framework 'could not load assembly' error message

    Cure for Entity Framework Migrations could not load assembly error message

    I usually setup a new solution so that it contains multiple projects. There's a project for web files, data files, services, utilities and so on. When I downloaded and setup Entity Framework through Nuget I installed it into my Project.Web (where all my views/controllers are) and to my Project.Data (where my data context is located with my repositories) projects.

    I installed EF Migrations to my Project.Data project as this is where my data context file lives. Everything compiles and run but sometimes when using Entity Framework Migrations I noticed that I was getting an error:

    Could not load assembly 'Project.Data'. (If you are using Code First Migrations inside Visual Studio this can happen if the startUp project for your solution does not reference the project that contains your migrations. You can either change the startUp project for your solution or use the -StartUpProjectName parameter.)

  • There is already an open DataReader associated with this Command which must be closed first

    I was working on one of my Entity Framework Code First websites the other day when I noticed the following error being returned to me:

    There is already an open DataReader associated with this Command which must be closed first

    Doing a few searches online I could see some of the solutions were to include the parameter 'MultipleActiveResultSets=True' in your entity framework setting in the web.config. However, when I checked my web.config to look for this setting I noticed that I did actually have it all setup as expected.

    Doing some more digging around I noticed that the cause for this issue is down to an issue with deferred execution in some of my queries.

    The solution was to add a simple .ToList() at the end of my query.

    A simple fix but one that drove me nuts for a while!

  • Entity Framework v4.2 upgrade not working

    This particular error caused me some headaches so I decided to blog about it in the hope that it'll help some other poor soul! I have a pretty standard MVC 3 project that uses Entity Framework Code First for handling the database side of things. I decided to update my project to ensure it was using the latest version of all of the packages in use on my project (ninject/entity framework/etc). This particular project was using Entity Framework v4.1, which I had previously updated using NuGet without any problems, so I decided to download and install the latest version from NuGet - ver 4.2.

Updates

Follow me online at TwitterFacebook or Flickr. If you want to get in touch with me try emailing me.

Latest Tweets