I made Web Forms, Ajax, Javascript, EF, SL4, Domain Services but I never worked with MVC and I wanted to get my hands on it.
I have a database on the SQL Azure that I wanted to expose by a REST interface for CRUD operations. Use the REST service in a HTML5/CSS3/JQuery application with the idea in mind that other applications could use the REST service later so the two applications
will be distinct.
I need help because I don't know if my choice of technologies will fit togheter and my first try ended up with an error.
I have created my database, opened VS2010 and installed ASP.NET MVC 4 for Visual Studio 2010 SP1.
I created a new MVC4-Web API project, added an EDMX over my SQL Azure DB in my solution and tried to add a controller for one of my tables.
This table is called: "Application" so I named the controller: ApplicationController, selected the template: "API Controller with r/w actions using EF. Selected the model Application and the data context Application too but I have to admit I don't really
know what those two are.
When I click on Add, I have this message: "Unsupported context type." !!
I found on the web that I am not alone but I couldn't find any solution.
Should I move to EF5 ? Can it work well with VS2010, SQL Azure and Web API ? Developping this project quickly is also important to me so I was hoping that MVC and EF would save me a lot of typing. In my DB, I have about 5 major tables with 2-3 other tables
to link them and 2 lookup tables, not very big but near 5 screens to design with grids to enable CRUD operation on this data.
The context class is for the database access. For generated code, you need the context to be of type DbContext instead of ObjectContext. You should look at what base class the context class is using. This article may also help you:
Thanks, it helped me a lot to understand a few more things with MVC.
Unfortunatly, I get to a new error !! I am not sure if Scaffolding was planned for MVC4 and Web API...
I believe I did as in the blog, except that I have more tables in my EDMX (Application, Server, Environment to name a few), I installed Scaffolding and runned: {scaffold controller MyInventory5Service.Models.Application -force -repository -DbContextType
"MyInventory5Service.Models.MyInventory5Entities"} trying to specify the complete names with namespaces but I got this error:
Oups, I tried it again, several hours later and it worked !!!! :-)
As said in the blog, I had to specify the Keys in the models as EF4 haven't seen it from the DB, then I have runned the Scaffold for each model and now, I have my controllers, my Views and it works !!!
But, it doesn't seem to be what I expected from a Web API application, should I only create new controllers, hoping that now it works ? What should I do to turn this into a "Web API" application ?
I tried again, new database, new Web API project, new EDMX, used the EF DbContext Generator and used again the create controller and now it worked !! I guess it was not clear to me before that the Data Context Class was the class to give access to
my Entities, I didn't used Scaffolding and now, I was able to create all my controllers for a Web API application.
Thanks a lot, I hope these comments will help anyone in the futur.
ClaudeVernie...
Member
26 Points
35 Posts
Need help to choose the most appropriate tool, and about error message: "Unsupported context type...
Nov 23, 2012 09:03 PM|LINK
Hello,
I made Web Forms, Ajax, Javascript, EF, SL4, Domain Services but I never worked with MVC and I wanted to get my hands on it.
I have a database on the SQL Azure that I wanted to expose by a REST interface for CRUD operations. Use the REST service in a HTML5/CSS3/JQuery application with the idea in mind that other applications could use the REST service later so the two applications will be distinct.
I need help because I don't know if my choice of technologies will fit togheter and my first try ended up with an error.
I have created my database, opened VS2010 and installed ASP.NET MVC 4 for Visual Studio 2010 SP1.
I created a new MVC4-Web API project, added an EDMX over my SQL Azure DB in my solution and tried to add a controller for one of my tables.
This table is called: "Application" so I named the controller: ApplicationController, selected the template: "API Controller with r/w actions using EF. Selected the model Application and the data context Application too but I have to admit I don't really know what those two are.
When I click on Add, I have this message: "Unsupported context type." !!
I found on the web that I am not alone but I couldn't find any solution.
Should I move to EF5 ? Can it work well with VS2010, SQL Azure and Web API ? Developping this project quickly is also important to me so I was hoping that MVC and EF would save me a lot of typing. In my DB, I have about 5 major tables with 2-3 other tables to link them and 2 lookup tables, not very big but near 5 screens to design with grids to enable CRUD operation on this data.
Thanks for any advice, best regards.
Claude
ozkary
Contributor
2034 Points
303 Posts
Re: Need help to choose the most appropriate tool, and about error message: "Unsupported context ...
Nov 24, 2012 03:05 AM|LINK
The context class is for the database access. For generated code, you need the context to be of type DbContext instead of ObjectContext. You should look at what base class the context class is using. This article may also help you:
http://ozkary.blogspot.com/2012/10/database-first-development-with-aspnet.html
hope it helps
og-bit.com
ClaudeVernie...
Member
26 Points
35 Posts
Re: Need help to choose the most appropriate tool, and about error message: "Unsupported context ...
Nov 24, 2012 06:39 PM|LINK
Thanks, it helped me a lot to understand a few more things with MVC.
Unfortunatly, I get to a new error !! I am not sure if Scaffolding was planned for MVC4 and Web API...
I believe I did as in the blog, except that I have more tables in my EDMX (Application, Server, Environment to name a few), I installed Scaffolding and runned: {scaffold controller MyInventory5Service.Models.Application -force -repository -DbContextType "MyInventory5Service.Models.MyInventory5Entities"} trying to specify the complete names with namespaces but I got this error:
Oups, I tried it again, several hours later and it worked !!!! :-)
As said in the blog, I had to specify the Keys in the models as EF4 haven't seen it from the DB, then I have runned the Scaffold for each model and now, I have my controllers, my Views and it works !!!
But, it doesn't seem to be what I expected from a Web API application, should I only create new controllers, hoping that now it works ? What should I do to turn this into a "Web API" application ?
Thank you so much !!!
Claude
:-)
ClaudeVernie...
Member
26 Points
35 Posts
Re: Need help to choose the most appropriate tool, and about error message: "Unsupported context ...
Nov 25, 2012 12:19 PM|LINK
It is perfect now !!
I tried again, new database, new Web API project, new EDMX, used the EF DbContext Generator and used again the create controller and now it worked !! I guess it was not clear to me before that the Data Context Class was the class to give access to my Entities, I didn't used Scaffolding and now, I was able to create all my controllers for a Web API application.
Thanks a lot, I hope these comments will help anyone in the futur.
Best regards,
Claude