Just recreated the Music Store Tutorial for the umpteenth time and hit upon this error message:
Error 1 The type or namespace name 'DropCreateDatabaseIfModelChanges' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Alphauser\my documents\visual studio 2010\Projects\TutorialMusicStore 03-04a\TutorialMusicStore
03-04a\Models\SampleData.cs 9 31 TutorialMusicStore 03-04a
Error 2 The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Alphauser\my documents\visual studio 2010\Projects\TutorialMusicStore 03-04a\TutorialMusicStore 03-04a\Models\MusicStoreEntities.cs 9 39 TutorialMusicStore
03-04a
I've included an abridged "SampleData.cs" file, including the line indicated in the error, and the "MusicStoreEntities.cs" code below.
Any input on how to get this to work would be greatly appreciated.
_________________________
SampleData.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace TutorialMusicStore_03_04a.Models
{
public class SampleData : DropCreateDatabaseIfModelChanges<MusicStoreEntities> <- Error
{
protected override void Seed(MusicStoreEntities context)
{
var genres = new List<Genre>
{
new Genre { Name = "Rock" },
new Genre { Name = "Jazz" },
new Genre { Name = "Metal" },
...
};
var artists = new List<Artist>
{
new Artist { Name = "Aaron Copland & London Symphony Orchestra" },
new Artist { Name = "Aaron Goldberg" },
new Artist { Name = "AC/DC" },
...
};
new List<Album>
{
new Album { Title = "A Copland Celebration, Vol. I", Genre = genres.Single(g => g.Name == "Classical"), Price = 8.99M, Artist = artists.Single(a => a.Name == "Aaron Copland & London Symphony Orchestra"), AlbumArtUrl = "/Content/Images/placeholder.gif"
},
new Album { Title = "Worlds", Genre = genres.Single(g => g.Name == "Jazz"), Price = 8.99M, Artist = artists.Single(a => a.Name == "Aaron Goldberg"), AlbumArtUrl = "/Content/Images/placeholder.gif" },
new Album { Title = "For Those About To Rock We Salute You", Genre = genres.Single(g => g.Name == "Rock"), Price = 8.99M, Artist = artists.Single(a => a.Name == "AC/DC"), AlbumArtUrl = "/Content/Images/placeholder.gif" },
...
}.ForEach(a => context.Albums.Add(a));
}
}
}
_________________________
MusicStoreEntities.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace TutorialMusicStore_03_04a.Models
{
public class MusicStoreEntities : DbContext
{
public DbSet<Album> Albums { get; set; }
public DbSet<Genre> Genres { get; set; }
}
}
Thanks for the suggestion. I'm trying to stick with the directions in the tutorial before turing to extra-tutorial means. I'm hoping there is an error in my code that can be pointed out to me. I'll keep you posted when I break through.
The SampleData is an imported file with no indication in the tutorial that it needs to be edited in any way. And with the difficulty of putting this all together for the first time, I haven't been volunteering making changes that are not prescribed in the
tutorial.
I'm not sure how to do that, but I'll start looking for how to do that..."importing a missing directive"
- At one point, Create, Edit, Review views automatically were being created on this computer...so not sure how it would have gotten uninstalled.
- Error message didn't explicitly point to EF, which had most who offered help over past month looking elsewhere for solution.
Don't really care about why though at this point so much as just being able to move forward coding after a month or more of being stalled.
I was hesitant to try, what seemed to me to be, a third party "Nuget" component. I didn't realize that this was just an installation of EF. Entirely my mistake.
3v3rhart
Member
159 Points
317 Posts
Music Store Tutorial, Error: 'DropCreateDatabaseIfModelChanges'
Jun 23, 2012 03:12 PM|LINK
Just recreated the Music Store Tutorial for the umpteenth time and hit upon this error message:
Error 1 The type or namespace name 'DropCreateDatabaseIfModelChanges' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Alphauser\my documents\visual studio 2010\Projects\TutorialMusicStore 03-04a\TutorialMusicStore 03-04a\Models\SampleData.cs 9 31 TutorialMusicStore 03-04a
Error 2 The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Alphauser\my documents\visual studio 2010\Projects\TutorialMusicStore 03-04a\TutorialMusicStore 03-04a\Models\MusicStoreEntities.cs 9 39 TutorialMusicStore 03-04a
I've included an abridged "SampleData.cs" file, including the line indicated in the error, and the "MusicStoreEntities.cs" code below.
Any input on how to get this to work would be greatly appreciated.
_________________________
SampleData.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace TutorialMusicStore_03_04a.Models
{
public class SampleData : DropCreateDatabaseIfModelChanges<MusicStoreEntities> <- Error
{
protected override void Seed(MusicStoreEntities context)
{
var genres = new List<Genre>
{
new Genre { Name = "Rock" },
new Genre { Name = "Jazz" },
new Genre { Name = "Metal" },
...
};
var artists = new List<Artist>
{
new Artist { Name = "Aaron Copland & London Symphony Orchestra" },
new Artist { Name = "Aaron Goldberg" },
new Artist { Name = "AC/DC" },
...
};
new List<Album>
{
new Album { Title = "A Copland Celebration, Vol. I", Genre = genres.Single(g => g.Name == "Classical"), Price = 8.99M, Artist = artists.Single(a => a.Name == "Aaron Copland & London Symphony Orchestra"), AlbumArtUrl = "/Content/Images/placeholder.gif" },
new Album { Title = "Worlds", Genre = genres.Single(g => g.Name == "Jazz"), Price = 8.99M, Artist = artists.Single(a => a.Name == "Aaron Goldberg"), AlbumArtUrl = "/Content/Images/placeholder.gif" },
new Album { Title = "For Those About To Rock We Salute You", Genre = genres.Single(g => g.Name == "Rock"), Price = 8.99M, Artist = artists.Single(a => a.Name == "AC/DC"), AlbumArtUrl = "/Content/Images/placeholder.gif" },
...
}.ForEach(a => context.Albums.Add(a));
}
}
}
_________________________
MusicStoreEntities.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace TutorialMusicStore_03_04a.Models
{
public class MusicStoreEntities : DbContext
{
public DbSet<Album> Albums { get; set; }
public DbSet<Genre> Genres { get; set; }
}
}
delislem
Member
12 Points
1 Post
Re: Music Store Tutorial, Error: 'DropCreateDatabaseIfModelChanges'
Jun 30, 2012 01:55 AM|LINK
Have you tried getting the entity framework nuget package?
Under your project folder: Reference, manage nuget packages.
3v3rhart
Member
159 Points
317 Posts
Re: Music Store Tutorial, Error: 'DropCreateDatabaseIfModelChanges'
Jul 03, 2012 02:08 PM|LINK
Thanks for the suggestion. I'm trying to stick with the directions in the tutorial before turing to extra-tutorial means. I'm hoping there is an error in my code that can be pointed out to me. I'll keep you posted when I break through.
Thanks again.
Dean
EhsanMubeen
Member
433 Points
100 Posts
Re: Music Store Tutorial, Error: 'DropCreateDatabaseIfModelChanges'
Jul 05, 2012 05:20 AM|LINK
Try replacing
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<MusicStoreEntities>()); with
Database.SetInitializer(new DropCreateDatabaseAlways<MusicStoreEntities>());
in your Global.asax file. Hope that will do the trick
Mark As Answer if my reply helped you
Pray|Game|Code - My Way of Living
vogelra
Member
44 Points
20 Posts
Re: Music Store Tutorial, Error: 'DropCreateDatabaseIfModelChanges'
Jul 10, 2012 03:20 AM|LINK
3v3rhart
Member
159 Points
317 Posts
Re: Music Store Tutorial, Error: 'DropCreateDatabaseIfModelChanges'
Jul 12, 2012 03:18 PM|LINK
The SampleData is an imported file with no indication in the tutorial that it needs to be edited in any way. And with the difficulty of putting this all together for the first time, I haven't been volunteering making changes that are not prescribed in the tutorial.
I'm not sure how to do that, but I'll start looking for how to do that..."importing a missing directive"
Thanks for the suggestion.
3v3rhart
Member
159 Points
317 Posts
Re: Music Store Tutorial, Error: 'DropCreateDatabaseIfModelChanges'
Jul 12, 2012 03:25 PM|LINK
Tried it...no change; but thanks for the suggestion.
3v3rhart
Member
159 Points
317 Posts
Re: Music Store Tutorial, Error: 'DropCreateDatabaseIfModelChanges'
Jul 20, 2012 03:33 PM|LINK
Answer ended up being...
EF not installed...at all.
confusing to me because...
- At one point, Create, Edit, Review views automatically were being created on this computer...so not sure how it would have gotten uninstalled.
- Error message didn't explicitly point to EF, which had most who offered help over past month looking elsewhere for solution.
Don't really care about why though at this point so much as just being able to move forward coding after a month or more of being stalled.
I was hesitant to try, what seemed to me to be, a third party "Nuget" component. I didn't realize that this was just an installation of EF. Entirely my mistake.
Thanks again
Dean