Followling the ASP.NET MVC Tutorials, Chapter 2 Get Started with ASP.NET MVC3,
I have created a Model class, Game.vb and a connectionString with our SQL Server 2008 database.
Game.vb
Imports
System.Data.Entity Public Class
Game
PublicProperty
ID() As
Integer PublicProperty
Title() As
String PublicProperty
ReleaseDate() As
Date
PublicProperty
Genre() AsString
PublicProperty
Price() AsDecimal
End
Class
Public Class
GameDBContext
Inherits
DbContext
PublicProperty
Games() AsDbSet(OfGame)
End
Class
ConnectionString in web.config <addname="GameDBContext"connectionString="Data
Source=MyWebServer;Initial Catalog=Games;Persist Security Info=True;User ID=aaa;Password=bbbccc"providerName="System.Data.SqlClient"
/>
Then, I tried to create a new controller using Entity Framework, as shown below. (MvcMovies is the name of the MVC project.) Add Controller:
Name: GameController
Template: Controller with read/write actions and views, using Entuty Framework
Model class: Game(MvcMovies)
Data context class: GameDBContext(MvcMovie)
Views: Razor(VBHTML)
Error message popped up. Waht's wronng?
Error: Unable to retrieve metadata for an ASP.NET MVC model, 'MvcMovie.Game'.
Could not find the CLR type for 'MvcMovie.Game'.
In addition to creating the Game.vb, then GameController, I have successfully created 2 ADO.NET EDM's,
Movies.edmx and MovieCategories.edmx. Two connectionStrings with names, databasenameEntity, were
created automatically in the web.config for these 2 edmx modelx. Then 2 controllers were created
successfully for accessing these 2 edmx models.
For the Code-First Game,vb model class, why I can not create a controller for this model?
What does "can not find the CLR type for MvcMovie.Game: mean??? My understanding is
the Games database will be created in SQL Server database automatically. I am sure the
user name can create new database.
To make sure I did not misss something from Microsoft Entity Framework, I installed
ADO.NET Entity Framework Feature CTP5, in addition to EF 4.1. Still got the same error msg.
In this ASP.NET MVC Tutorials, Chapter 2 Get Started with ASP.NET MVC3, the 'Adding a Model' section
asked us to use the 'EF Code First' to create a model class, then in the following section 'Accessing your
Model's Data from a Controller' we can create a new controller based on this model class with a DBContext class.
Somehow I still got the erro -- Unable to retrieve metadata for 'MvcMovie.Game'. Could not find the CLR type
for 'MvcMovie.Game'. MvcMovie is the name of the ASP.NET MVC project and Game is the name of model.
Checking the version of the VS 2010 found:
Microsoft Visual Studio 2010
Version 10.0.40219.1 SP1Rel
Microsoft.NET Framework
Versiobn 4.0.30319 SP1Rel
Also the Program Files of C:\ drive showed Microsoft ADO.NET Entity Framework Feature CTP5 and Microsoft.NET Entity Framework 4.1
Any answers for my 'Could not find the CLR type' error?
No answers, I'm afraid - just more questions... ;)
I'm new to ASP.Net & having the exact same issues - I'm using SQL Server 2008 as well. I'm sure my connection string is good, as I got Linq to generate one & it is the same
I had no probelm to create the code-first controller. In this EF Data Model project, the database context was created in a DAL folder.
In another MVC project with problems in creating a new controller, I had several classes in the Model folder, including the
MovieVB.vb and Movie.edmx. I am not sure if this is the problem. Anyway, just follow the above link to create an EF data model for a code-first new controller.
wonjartran
Participant
907 Points
1214 Posts
Can not create a new Controller to access a Model class using ADO.NET Entity Framework 4.1
Mar 06, 2012 03:24 PM|LINK
Followling the ASP.NET MVC Tutorials, Chapter 2 Get Started with ASP.NET MVC3,
I have created a Model class, Game.vb and a connectionString with our SQL Server 2008 database.
Game.vb
Imports System.Data.Entity
Public Class Game
Public Property ID() As Integer
Public Property Title() As String
Public Property ReleaseDate() As Date
Public Property Genre() As String
Public Property Price() As Decimal
End Class
Public Class GameDBContext
Inherits DbContext
Public Property Games() As DbSet(Of Game)
End Class
ConnectionString in web.config
<add name="GameDBContext" connectionString="Data Source=MyWebServer;Initial Catalog=Games;Persist Security Info=True;User ID=aaa;Password=bbbccc" providerName="System.Data.SqlClient" />
Then, I tried to create a new controller using Entity Framework, as shown below. (MvcMovies is the name of the MVC project.)
Add Controller:
Name: GameController
Template: Controller with read/write actions and views, using Entuty Framework
Model class: Game(MvcMovies)
Data context class: GameDBContext(MvcMovie)
Views: Razor(VBHTML)
Error message popped up. Waht's wronng?
Error: Unable to retrieve metadata for an ASP.NET MVC model, 'MvcMovie.Game'.
Could not find the CLR type for 'MvcMovie.Game'.
wonjartran
Participant
907 Points
1214 Posts
Re: Can not create a new Controller to access a Model class using ADO.NET Entity Framework 4.1
Mar 06, 2012 04:45 PM|LINK
FYI: Below is the connectionString in the web.config for the SQL Server Compact database, as shown in the Tutorial.
<add name="MovieDBContext"
connectionString="Data Source=|DataDirectory|Movies.sdf"
providerName="System.Data.SqlServerCe.4.0"/>
wonjartran
Participant
907 Points
1214 Posts
Re: Can not create a new Controller to access a Model class using ADO.NET Entity Framework 4.1
Mar 06, 2012 06:54 PM|LINK
In addition to creating the Game.vb, then GameController, I have successfully created 2 ADO.NET EDM's,
Movies.edmx and MovieCategories.edmx. Two connectionStrings with names, databasenameEntity, were
created automatically in the web.config for these 2 edmx modelx. Then 2 controllers were created
successfully for accessing these 2 edmx models.
For the Code-First Game,vb model class, why I can not create a controller for this model?
What does "can not find the CLR type for MvcMovie.Game: mean??? My understanding is
the Games database will be created in SQL Server database automatically. I am sure the
user name can create new database.
wonjartran
Participant
907 Points
1214 Posts
Re: Can not create a new Controller to access a Model class using ADO.NET Entity Framework 4.1
Mar 06, 2012 07:03 PM|LINK
I created the Games database with the SSMS. Tried to create the GameController again,
still got the same error.
wonjartran
Participant
907 Points
1214 Posts
Re: Can not create a new Controller to access a Model class using ADO.NET Entity Framework 4.1
Mar 09, 2012 03:27 PM|LINK
To make sure I did not misss something from Microsoft Entity Framework, I installed
ADO.NET Entity Framework Feature CTP5, in addition to EF 4.1. Still got the same error msg.
raduenuca
All-Star
24675 Points
4250 Posts
Re: Can not create a new Controller to access a Model class using ADO.NET Entity Framework 4.1
Mar 09, 2012 03:40 PM|LINK
Have you compiled the project? You need to compile in order to use scaffolding
Radu Enuca | Blog
wonjartran
Participant
907 Points
1214 Posts
Re: Can not create a new Controller to access a Model class using ADO.NET Entity Framework 4.1
Mar 09, 2012 03:46 PM|LINK
Yes, I clicked the Build menu to build the Project.
wonjartran
Participant
907 Points
1214 Posts
Re: Can not create a new Controller to access a Model class using ADO.NET Entity Framework 4.1
Apr 09, 2012 04:10 PM|LINK
In this ASP.NET MVC Tutorials, Chapter 2 Get Started with ASP.NET MVC3, the 'Adding a Model' section
asked us to use the 'EF Code First' to create a model class, then in the following section 'Accessing your
Model's Data from a Controller' we can create a new controller based on this model class with a DBContext class.
Somehow I still got the erro -- Unable to retrieve metadata for 'MvcMovie.Game'. Could not find the CLR type
for 'MvcMovie.Game'. MvcMovie is the name of the ASP.NET MVC project and Game is the name of model.
Checking the version of the VS 2010 found:
Microsoft Visual Studio 2010
Version 10.0.40219.1 SP1Rel
Microsoft.NET Framework
Versiobn 4.0.30319 SP1Rel
Also the Program Files of C:\ drive showed Microsoft ADO.NET Entity Framework Feature CTP5 and Microsoft.NET Entity Framework 4.1
Any answers for my 'Could not find the CLR type' error?
everynameich...
Member
6 Points
10 Posts
Re: Can not create a new Controller to access a Model class using ADO.NET Entity Framework 4.1
May 09, 2012 06:28 AM|LINK
Hello Mate,
No answers, I'm afraid - just more questions... ;)
I'm new to ASP.Net & having the exact same issues - I'm using SQL Server 2008 as well. I'm sure my connection string is good, as I got Linq to generate one & it is the same
(connectionString="Data Source=myMachine;Initial Catalog=MyDB;Integrated Security=True"
providerName="System.Data.SqlClient")
When I try to add the controller class it throws exactly the same error. Did you ever resolve this? If so, what was the problem/solution?
Thanks!
wonjartran
Participant
907 Points
1214 Posts
Re: Can not create a new Controller to access a Model class using ADO.NET Entity Framework 4.1
May 09, 2012 03:56 PM|LINK
First, my problem was with the so-called code first, not model first or database first. Later on I tried another ASP.NET MVC Tutorial,
http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application
I had no probelm to create the code-first controller. In this EF Data Model project, the database context was created in a DAL folder.
In another MVC project with problems in creating a new controller, I had several classes in the Model folder, including the MovieVB.vb and Movie.edmx. I am not sure if this is the problem. Anyway, just follow the above link to create an EF data model for a code-first new controller.