0

I've installed EFCodeFirst 0.8 (CTP5) and EFCodeFirst.SQLServerCompact 0.8.84821. I've updated the references to EntityFramework and System.Data.SqlServerCe.Entity.dll. My project compiles and runs, with one exception: I can not call Database.SetInitializer.

Here is how my code looks:

using System.Data.Entity;

namespace Recipes.Models
{
    public class RecipesEntities : DbContext
    {
        public RecipesEntities()
        {

            System.Data.Entity.Database.SetInitializer<RecipesEntities>(new SampleData());
            //Database.SetInitializer<RecipesEntities>(new SampleData());
        }

        public DbSet<Category> Categories { get; set; }
        ...
    }
}

and the error I get is

The type or namespace 'SetInitializer' does not exist in the namespace 'System.Data.Entity.Database

Indeed, it does not show up in the Intellisense. However, as I said - if I comment out the line that calls SetInitializer, the project compiles and runs. I can not test it properly though cause most operations depend on some seed data in the DB.

What could be the reason for such behaviour?

Evgeny
  • 3,320
  • 7
  • 39
  • 50
  • Try to add a "using EntityFramework;" – ErikEJ Aug 13 '12 at 06:18
  • EF 0.8? Why are you using CTP of EF4.1 when EF 4.3.1 RTM was shipped long time ago and EF 5.0 RC is available. – Ladislav Mrnka Aug 13 '12 at 09:14
  • Maybe I'm just hopelessly stuck in the past. Or maybe it's just that burning sensation feeling when you upgrade from x to x.1 and get hurt, and then you think ... to upgrade from x to x+1 would then hurt 10 times more, wouldn't it? Anyway, that's my ongoing project to teach myself MVC, not a production website. In fact, I gave up for now on that upgrade - I shldn't have done it in the first place, I should've just selected Project -> Add Deployable Dependencies -> check SQL Server Compact, that was what fixed my original problem. Nevertheless, one day I'll be there where the cool guys hang out – Evgeny Aug 13 '12 at 12:44
  • You really should upgrade, especially when it is for learning! Take MVC4, EF5. Switching between paradigms is one of the major skills of a software developer, not knowing the tricks. – Gert Arnold Aug 14 '12 at 07:09
  • You convinced me ... Upgrading to MVC4 was not too bad - I created a new MVC4 project, added all existing views, controllers, viewmodels and helpers, added changes that I made to web.config, added css, added scripts, added images ... was a good opportunity to clean up some scripts I don't seem to use, but they were referenced. Overall, no code changes were required which is very positive. Could not upgrade to EF5 yet cause it needs .NET 4.5 which I can not install at work where I sometimes stay after hours ... but installed EF4.3 instead of 4.1 – Evgeny Aug 14 '12 at 23:08

0 Answers0