0

I am building the MSV Music Store http://www.asp.net/mvc/tutorials/mvc-music-store

I ran into a roadblock where there was an issue with the Entity Framework.

using System.Data.Entity;

namespace MvcMusicStore.Models
{
  public class MusicStoreEntities : DbContext
  {
      public DbSet<Album> Albums { get; set; }
      public DbSet<Genre> Genres { get; set; }
  }
}

There error I was getting was...

Error 1 The type or namespace name 'DBContext' could not be found (are you missing a using directive or an assembly reference?) C:\ASP\MvcMusicStore\Models\MusicStoreEntities.cs 8 39 MvcMusicStore

I then found this question where there was a similar problem...

The type or namespace name 'DbContext' could not be found

EDIT: Using this question I had added the "system.data.entity" reference but was still experiencing the same error.

But then I saw another answer there that resolved the issue which said to change DbContext to System.Data.Entity.DbContext

This has resolved my issue.

I'm wondering why, as I'm unsure of the purpose having to include System.Data.Entity, and why simply adding the reference didnt work.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Adrian
  • 1,976
  • 5
  • 41
  • 105
  • See this answer: http://stackoverflow.com/a/5741167/2777098 – display name Apr 08 '14 at 16:33
  • Thanks, but I think I need to edit the question, as I tried that and I was still getting the error. – Adrian Apr 08 '14 at 16:37
  • 2
    Your question is very confusing. It said you solved the problem; then still have problem. **Please edit your question.** – Win Apr 08 '14 at 16:39
  • Ive edited it now, apologies the point i was making was that adding the reference didnt work, but literally typing `system.data.entity` did the job. I just dont know why – Adrian Apr 08 '14 at 16:42
  • That's why I referenced this SO answer that explains why: stackoverflow.com/a/5741167/2777098 – display name Apr 08 '14 at 16:43
  • 1
    @Adrian IsabelHM's [link](http://stackoverflow.com/a/5741167/2777098) and the SO [link](http://stackoverflow.com/questions/5741109/the-type-or-namespace-name-dbcontext-could-not-be-found) in your question already answer your quesiton - **Im wondering why?** – Win Apr 08 '14 at 16:44
  • Just to aid understanding a little more, these types of issues are unfortunately pretty common with .NET. Microsoft decided to make certain pieces of .NET nuget packages so they could be updated independently of the core. That's a good thing. However, most of these nuget packages merely extend existing namespaces in .NET. In particular here, `System.Data.Entity` exists in .NET without Entity Framework, but `System.Data.Entity.DbContext` comes from EntityFramework.dll, and doesn't exist unless that nuget is installed. Sometimes including the namespace isn't enough. – Chris Pratt Apr 08 '14 at 17:59

0 Answers0