Last post Apr 11, 2012 08:02 AM by Young Yang - MSFT
Apr 09, 2012 05:19 PM|wonjartran|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
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.
Apr 09, 2012 05:27 PM|CodeHobo|LINK
Did you rebuild the project before trying to add a new controller? Try that first.
Apr 09, 2012 06:52 PM|wonjartran|LINK
Yes. I clicked rebuild solution and tried again. Still got the same error.
Here is the Game.vb model 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.
Source=SCA3a5b;Initial Catalog=Game;Persist Security Info=True;User ID=WWW;Password=wwwwwwwww1"
Apr 09, 2012 07:03 PM|wonjartran|LINK
Just noticed that the MvcMovie project does not have the "Reference" folder,
where the EntityFramework is listed. Why?
Apr 09, 2012 07:16 PM|CodeHobo|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.
Apr 09, 2012 07:30 PM|wonjartran|LINK
Thanks. Yes, I found the EntityFramework 188.8.131.52 from the References tab on the project Properties.
So why 'Could not find the CLR type'? Something wrong with coding Game.vb??? DbContext???
Apr 09, 2012 09:24 PM|wonjartran|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.
Apr 09, 2012 09:30 PM|CodeHobo|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.
Apr 09, 2012 09:52 PM|wonjartran|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?
Apr 11, 2012 08:02 AM|Young Yang - MSFT|LINK
Change your connectionString and providerName to this:
<add name="GameDBContext" connectionString="Data Source=|DataDirectory|Game.sdf" providerName="System.Data.SqlServerCe.4.0"/>
Hope this helpful