Entity Framework CRUD creation working only if the "Data context class" does NOT match the "add name" variable in the web.config Connection string.
RSS
Unable to retrieve metadata for 'MvcMusicStore.Models.Album'. Using the same DbCompiledModel to create contexts against different types of database servers is not supported. Instead, create a separate DbCompiled Model for each type of server being used.
__________________________
Successful:
Data context class: MusicStoreEntities (MvcMusicStore.Models)
<connectionStrings>
<add name="randomname" ...
Environment: virtually new install of OS (XP), MVC 4, and MVS 2010, SQL Compact 4 / Project: Music Store Tutorial - Step 5
Note: The successful version of the configuration above displays no error message and allows continuation with the tutorial as if there is no problem. It has been suggested to me, on good authority, that although I am able to proceed with the tutorial,
the data that I'm pointing to may be a problem (that there may be two data sources at this point which may be a problem in the future).
I did install SQL Compact 4, in addition to any SQL version that was - or was not - included in the one-click install of ASP.net MVC4 provided on ASP.net. Installing SQL Compact 4 addressed a previous and fairly recent problem, but I'm thinking it may be the
source of confusion regarding to what data I'm pointing now.
Can you post your full connection strings (no un/pw please) and your DbContext class? Also, what DB would you *like* to use?
Direction I'm going here: I would make sure my DbContext is calling the base constructor to name the connection as part A, part B would be to see what you want to connect to/use versus what is actually being crufted out for you.
It only works if I change the "add name" variable in the web.config connection string, pictured above as it should be - "MusicStoreEntities" - to anything other. In the project that I have successfully working the "add name" variable is "randomname".
(if there is another way of showing the database context other than the parameters I'm selecting in the "Add Controller" dialog box that I've shown above, please let me know...I'm still quite new to this)
***********************
Re: "Database I would *like* to use":
1. There is a "MusicStoreEntities.cs" model ("database"? Not exactly sure how interchangable the terms model and database technically are) item at MvcMusicStore / Models / MusicStoreEntities.cs
2. The database was created from data (called "SampleData.cs") supplied in an file attendant to the tutorial which is also an item at same model path MvcMusicStore / Models / SampleData.cs and referenced in the global.asax file in code below...
________________________
protected void Application_Start()
{
System.Data.Entity.Database.SetInitializer(
new MvcMusicStore.Models.SampleData());
________________________
3. AND there is a MvcMusicStore.sdf database item in the AppData folder in the OS (XP) but NO ITEMS APPEAR under the "App_Data" item within Soulution Explorer within MVS 2010 at MvcMusicStore / App_Data (which has concerned me).
Please let me know if I'm supplying you with the right or enough information.
Okay, I won't be able to fix this necessarily for you, but hopefully I can answer a few of your questions.
1) The model isn't exactly the database. But the class (and it's properties) that derives from DbContext is used to infer the database schema.
3) Don't be too concerned on this point. There is a button atop the Solution Explorer that hides/displays all items in the project folders. Your database does not need to be part of the solution, so it's not (by default) and it's not displayed (by default),
though you can override this behaviour.
Can you look for your DbContext class and post that here?
Besides indicating what I chose in the "Add Controller" dialog box, I'm not sure where I would find the dbcontext...I seached the web.config, global.asax, and store controller just to try to do due dilligence on my end, but I'm coming up with nothing. Can
you give me some further direction?
Just figured out how to do a global search of all files in project!
Seems the only reference to dbcontext is in the MusicStoreEntities file itself...
MvcMusicStore / MusicStoreEntities.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace MvcMusicStore.Models
{
public class MusicStoreEntities : DbContext
{
public DbSet<Album> Albums { get; set; }
public DbSet<Genre> Genres { get; set; }
}
}
I'll keep searching, but this might be one more piece of the puzzle.
3v3rhart
Member
159 Points
317 Posts
Entity Framework CRUD creation working only if the "Data context class" does NOT match the "add n...
Nov 17, 2012 07:58 PM|LINK
Unsuccessful:
Add Controller:
Data context class: MusicStoreEntities (MvcMusicStore.Models)
Web.config
<connectionStrings>
<add name= MusicStoreEntities ...
With the following error message:
__________________________
Microsoft Visual Web Developer 2010 Express
Unable to retrieve metadata for 'MvcMusicStore.Models.Album'. Using the same DbCompiledModel to create contexts against different types of database servers is not supported. Instead, create a separate DbCompiled Model for each type of server being used.
__________________________
Successful:
Data context class: MusicStoreEntities (MvcMusicStore.Models)
<connectionStrings>
<add name="randomname" ...
Environment: virtually new install of OS (XP), MVC 4, and MVS 2010, SQL Compact 4 / Project: Music Store Tutorial - Step 5
Note: The successful version of the configuration above displays no error message and allows continuation with the tutorial as if there is no problem. It has been suggested to me, on good authority, that although I am able to proceed with the tutorial, the data that I'm pointing to may be a problem (that there may be two data sources at this point which may be a problem in the future).
I did install SQL Compact 4, in addition to any SQL version that was - or was not - included in the one-click install of ASP.net MVC4 provided on ASP.net. Installing SQL Compact 4 addressed a previous and fairly recent problem, but I'm thinking it may be the source of confusion regarding to what data I'm pointing now.
Please advise. Thanks.
TheyCallMeMi...
Member
76 Points
18 Posts
Re: Entity Framework CRUD creation working only if the "Data context class" does NOT match the "a...
Nov 19, 2012 06:16 PM|LINK
Can you post your full connection strings (no un/pw please) and your DbContext class? Also, what DB would you *like* to use?
Direction I'm going here: I would make sure my DbContext is calling the base constructor to name the connection as part A, part B would be to see what you want to connect to/use versus what is actually being crufted out for you.
Cheers,
-James
3v3rhart
Member
159 Points
317 Posts
Re: Entity Framework CRUD creation working only if the "Data context class" does NOT match the "a...
Nov 19, 2012 07:07 PM|LINK
Thanks for your response!
The introductory "Music Store" tutorial calls for the following parameters...
_______________________
MvcMusicStore / Web.config
<connectionStrings>
<add name="MusicStoreEntities" connectionString="Data Source=|DataDirectory|MvcMusicStore.sdf" providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
_______________________
Add Controller (dialog box)
Data context class:
Selecting: MusicStoreEntities (MvcMusicStore.Models)
_______________________
Description:
It only works if I change the "add name" variable in the web.config connection string, pictured above as it should be - "MusicStoreEntities" - to anything other. In the project that I have successfully working the "add name" variable is "randomname".
(if there is another way of showing the database context other than the parameters I'm selecting in the "Add Controller" dialog box that I've shown above, please let me know...I'm still quite new to this)
***********************
Re: "Database I would *like* to use":
1. There is a "MusicStoreEntities.cs" model ("database"? Not exactly sure how interchangable the terms model and database technically are) item at MvcMusicStore / Models / MusicStoreEntities.cs
2. The database was created from data (called "SampleData.cs") supplied in an file attendant to the tutorial which is also an item at same model path MvcMusicStore / Models / SampleData.cs and referenced in the global.asax file in code below...
________________________
protected void Application_Start()
{
System.Data.Entity.Database.SetInitializer(
new MvcMusicStore.Models.SampleData());
________________________
3. AND there is a MvcMusicStore.sdf database item in the AppData folder in the OS (XP) but NO ITEMS APPEAR under the "App_Data" item within Soulution Explorer within MVS 2010 at MvcMusicStore / App_Data (which has concerned me).
Please let me know if I'm supplying you with the right or enough information.
Thanks again for wrestling with this.
TheyCallMeMi...
Member
76 Points
18 Posts
Re: Entity Framework CRUD creation working only if the "Data context class" does NOT match the "a...
Nov 19, 2012 07:14 PM|LINK
Okay, I won't be able to fix this necessarily for you, but hopefully I can answer a few of your questions.
1) The model isn't exactly the database. But the class (and it's properties) that derives from DbContext is used to infer the database schema.
3) Don't be too concerned on this point. There is a button atop the Solution Explorer that hides/displays all items in the project folders. Your database does not need to be part of the solution, so it's not (by default) and it's not displayed (by default), though you can override this behaviour.
Can you look for your DbContext class and post that here?
3v3rhart
Member
159 Points
317 Posts
Re: Entity Framework CRUD creation working only if the "Data context class" does NOT match the "a...
Nov 19, 2012 07:23 PM|LINK
Thanks for the information...it all adds up.
Besides indicating what I chose in the "Add Controller" dialog box, I'm not sure where I would find the dbcontext...I seached the web.config, global.asax, and store controller just to try to do due dilligence on my end, but I'm coming up with nothing. Can you give me some further direction?
3v3rhart
Member
159 Points
317 Posts
Re: Entity Framework CRUD creation working only if the "Data context class" does NOT match the "a...
Nov 19, 2012 07:31 PM|LINK
Just figured out how to do a global search of all files in project!
Seems the only reference to dbcontext is in the MusicStoreEntities file itself...
MvcMusicStore / MusicStoreEntities.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace MvcMusicStore.Models
{
public class MusicStoreEntities : DbContext
{
public DbSet<Album> Albums { get; set; }
public DbSet<Genre> Genres { get; set; }
}
}
I'll keep searching, but this might be one more piece of the puzzle.