In a Microsoft ASP.NET MVC Tutorial, 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 always 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
I have the VS 2010 SP1 installed, right!? 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? EF 4.1 is no good? TIA.
Yes. I clicked rebuild solution and tried again. Still got the same error.
Here is the Game.vb model class.
__________________________________________________________________________
Imports
System.Data.Entity Public Class
Game PublicProperty
ID() AsInteger PublicProperty
Title() As
String PublicProperty
ReleaseDate() As
Date
PublicProperty
Genre() AsString PublicProperty
Price() AsDecimal End
Class
Public Class
GameDBContext
InheritsDbContext PublicProperty
Games() AsDbSet(OfGame) End
Class
------------------------------------------------------------------------------------------------
And here is the GameDBContext in web.config. To the best of my knowledge, the Entity Framework will
create the database Game on the SQL Server. I should not manually create a 'Game' database by myself.
Right!?
The references folder only appears when using c# not VB.NET. Instead you can view your references by right clicking on the project node at the top of the solution explorer, then go to References (should be the last option). In the properties window there
is a references tab.
Anyway, I followed the C# tutorial to create a new ASP.NET MVC project.
After creating the Movie model class wit the MovieDBContext class. I got
no problems creating the MoviesController.
I started over again with a new ASP.net MVC project in VB, then created a VB model class.
Again I successflly created a new controller to access the VB model and a new database
was created in SQL Server.
All I can remmember is, in my old ASP.NET MVC project, I have created the so-called
database first model (.edmx) before I tried the code first model. Is this the problem?
wonjartran
Participant
907 Points
1214 Posts
POCO class erro -- Could not find the CLR type
Apr 09, 2012 04:19 PM|LINK
In a Microsoft ASP.NET MVC Tutorial, 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 always 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
I have the VS 2010 SP1 installed, right!? 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? EF 4.1 is no good? TIA.
CodeHobo
All-Star
18647 Points
2647 Posts
Re: POCO class erro -- Could not find the CLR type
Apr 09, 2012 04:27 PM|LINK
Did you rebuild the project before trying to add a new controller? Try that first.
Blog | Twitter : @Hattan
wonjartran
Participant
907 Points
1214 Posts
Re: POCO class erro -- Could not find the CLR type
Apr 09, 2012 05:52 PM|LINK
Yes. I clicked rebuild solution and tried again. Still got the same error.
Here is the Game.vb model class.
__________________________________________________________________________
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
------------------------------------------------------------------------------------------------
And here is the GameDBContext in web.config. To the best of my knowledge, the Entity Framework will
create the database Game on the SQL Server. I should not manually create a 'Game' database by myself.
Right!?
<add name="GameDBContext" connectionString="Data Source=SCA3a5b;Initial Catalog=Game;Persist Security Info=True;User ID=WWW;Password=wwwwwwwww1" providerName="System.Data.SqlClient"/>
wonjartran
Participant
907 Points
1214 Posts
Re: POCO class erro -- Could not find the CLR type
Apr 09, 2012 06:03 PM|LINK
Just noticed that the MvcMovie project does not have the "Reference" folder,
where the EntityFramework is listed. Why?
CodeHobo
All-Star
18647 Points
2647 Posts
Re: POCO class erro -- Could not find the CLR type
Apr 09, 2012 06:16 PM|LINK
The references folder only appears when using c# not VB.NET. Instead you can view your references by right clicking on the project node at the top of the solution explorer, then go to References (should be the last option). In the properties window there is a references tab.
Blog | Twitter : @Hattan
wonjartran
Participant
907 Points
1214 Posts
Re: POCO class erro -- Could not find the CLR type
Apr 09, 2012 06:30 PM|LINK
Thanks. Yes, I found the EntityFramework 4.1.0.0 from the References tab on the project Properties.
So why 'Could not find the CLR type'? Something wrong with coding Game.vb??? DbContext???
wonjartran
Participant
907 Points
1214 Posts
Re: POCO class erro -- Could not find the CLR type
Apr 09, 2012 08:24 PM|LINK
Anyway, I followed the C# tutorial to create a new ASP.NET MVC project.
After creating the Movie model class wit the MovieDBContext class. I got
no problems creating the MoviesController.
CodeHobo
All-Star
18647 Points
2647 Posts
Re: POCO class erro -- Could not find the CLR type
Apr 09, 2012 08:30 PM|LINK
Ok, glad to hear you got it working. I'll go try to do the VB.NET tutorial myself in a little bit and let you know if I run into any similar issues.
Blog | Twitter : @Hattan
wonjartran
Participant
907 Points
1214 Posts
Re: POCO class erro -- Could not find the CLR type
Apr 09, 2012 08:52 PM|LINK
I started over again with a new ASP.net MVC project in VB, then created a VB model class.
Again I successflly created a new controller to access the VB model and a new database
was created in SQL Server.
All I can remmember is, in my old ASP.NET MVC project, I have created the so-called
database first model (.edmx) before I tried the code first model. Is this the problem?
Young Yang -...
All-Star
21344 Points
1818 Posts
Microsoft
Re: POCO class erro -- Could not find the CLR type
Apr 11, 2012 07:02 AM|LINK
Hi
Change your connectionString and providerName to this:
Hope this helpful
Regards
Young Yang
Feedback to us
Develop and promote your apps in Windows Store