SampleData

May 31, 2011 at 9:41 AM
Edited May 31, 2011 at 9:51 AM

Hi Jon
I hve got 2 simmilar errors  "There is no implicit reference conversion from 'MvcMusicStore.Models.MusicStoreEntities' to 'System.Data.Entity.DbContext'" in


1/

protected void Application_Start()
{
System.Data.Entity.
Database .SetInitializer( new MvcMusicStore.Models.SampleData ());
....

2/public class SampleData : CreateDatabaseIfNotExists<MusicStoreEntitie
.......

 

 

 


error message is:
Error 1 The type 'MvcMusicStore.Models.MusicStoreEntities' cannot be used as type parameter 'TContext' in the generic type or method 'System.Data.Entity.CreateDatabaseIfNotExists<TContext>'. There is no implicit reference conversion from 'MvcMusicStore.Models.MusicStoreEntities' to 'System.Data.Entity.DbContext'. C:\Lam\Mindshare\MindShareIntranet\MvcMusicStore\MvcMusicStore\Models\SampleData.cs 10 18 MvcMusicStore

For the 1st error in Global.asax, I added a line in Web.config :
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
and it cleared the erroe in Global.asax , but this error keeps persisting in public class SampaleData

 Can you please advise what to do?

 Thanks

 Leo

 

 

Coordinator
Jun 11, 2011 at 6:39 AM

Does your entities class inherit from DbContext, like this?

using System.Data.Entity;

namespace MvcMusicStore.Models
{
    public class MusicStoreEntities : DbContext
    {
        public DbSet<Album> Albums { get; set; }
        public DbSet<Genre> Genres { get; set; }
        public DbSet<Artist> Artists { get; set; }
        public DbSet<Cart> Carts { get; set; }
        public DbSet<Order> Orders { get; set; }
        public DbSet<OrderDetail> OrderDetails { get; set; }
    }
}

Jun 11, 2011 at 8:48 AM
Hi Jon
Thank you for your email.
I have sorted out my problem and grateful to your MVCMusicStore!
Regards

On Sat, Jun 11, 2011 at 7:40 AM, jongalloway <notifications@codeplex.com> wrote:

From: jongalloway

Does your entities class inherit from DbContext, like this?

using System.Data.Entity;

namespace MvcMusicStore.Models
{
    public class MusicStoreEntities : DbContext
    {
        public DbSet<Album> Albums { get; set; }
        public DbSet<Genre> Genres { get; set; }
        public DbSet<Artist> Artists { get; set; }
        public DbSet<Cart> Carts { get; set; }
        public DbSet<Order> Orders { get; set; }
        public DbSet<OrderDetail> OrderDetails { get; set; }
    }
}

Read the full discussion online.

To add a post to this discussion, reply to this email (mvcmusicstore@discussions.codeplex.com)

To start a new discussion for this project, email mvcmusicstore@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Jun 10, 2012 at 9:01 PM

I did this ans I still got run time errors

One or more validation errors were detected during model generation:

System.Data.Edm.EdmEntityType: : EntityType 'Genre' has no key defined. Define the key for this EntityType.
System.Data.Edm.EdmEntitySet: EntityType: EntitySet �Genres� is based on type �Genre� that has no keys defined.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.Entity.ModelConfiguration.ModelValidationException: One or more validation errors were detected during model generation:

System.Data.Edm.EdmEntityType: : EntityType 'Genre' has no key defined. Define the key for this EntityType.
System.Data.Edm.EdmEntitySet: EntityType: EntitySet �Genres� is based on type �Genre� that has no keys defined.


Source Error:

Line 35:     //    new Genre { Name = "Rock"} 
Line 36:     //};
Line 37:             var genres = storeDB.Genres.ToList();
Line 38:             return View(genres); 
Line 39: 


Source File: D:\mvc\MvcMusicStoreDemo\MvcMusicStore\MvcMusicStore\Controllers\StoreController.cs Line: 37

Stack Trace:

[ModelValidationException: One or more validation errors were detected during model generation:

	System.Data.Edm.EdmEntityType: : EntityType 'Genre' has no key defined. Define the key for this EntityType.
	System.Data.Edm.EdmEntitySet: EntityType: EntitySet �Genres� is based on type �Genre� that has no keys defined.
]
   System.Data.Entity.ModelConfiguration
Coordinator
Jun 12, 2012 at 7:17 AM

@stevensrf1 I replied to you about this error on a separate discussion thread.