Unsupported Context Type when creating Controller

asp.net-mvc asp.net-mvc-4 c# entity-framework


New to .net unsure what I am doing wrong here. I created a c# API project and then used ADO.Net entity mappings. Which looks like it created correct .cs files for the models based on all of my tables. I guess the next step is to create a controller, but I get an error message when that happens.

Model 1

namespace GoogleMapsAPIv1.Models
    using System;
    using System.Collections.Generic;

    public partial class Table1
        public string COUNTRY_ID { get; set; }
        public string PROVINCE_ID { get; set; }
        public string CITY { get; set; }
        public string COUNTY { get; set; }
        public string POSTAL_CODE { get; set; }
        public Nullable<decimal> LATITUDE { get; set; }
        public Nullable<decimal> LONGITUDE { get; set; }
        public Nullable<decimal> DISTANCE_CACHED { get; set; }
        public string FIPS_PROVINCE_CODE { get; set; }
        public string FIPS_COUNTY_CODE { get; set; }
        public Nullable<System.DateTime> CREATED_DATE { get; set; }
        public Nullable<System.DateTime> LAST_MODIFIED_DATE { get; set; }
        public string SPATIAL_DATA { get; set; }
        public string TIMEZONE_ID { get; set; }
        public Nullable<int> GMT_OFF_SET { get; set; }
        public string SPATIAL_BOUNDARY { get; set; }
        public int DK_COUNTRY_ID { get; set; }

The error message I get when I set this model as the Model Class and the Data Context class is

Unsupported Context Type 

The template I was using is API controller with read/write actions, using Entity framework

10/25/2013 6:44:22 PM

Accepted Answer

Here are the steps I used to create a simple MVC API application

  1. Open visual studio 2012 and create a ASP.NET MVC v4 application
  2. Choose API
  3. in the Solutions explorer location the Model directory and right click and choose 'Add' > 'New Item'
  4. From 'Add New Item' locate ADO.Net Entity Data Model 5 . Go through ADO.NET wizard which will allow you to generate the connection to SQL Server
  5. Choose tables which you would like to build models for
  6. Once models are crated right click 'Controllers' and choose Add>Controller
  7. Choose Template -'API controller with read/write actions, using Entity Framework' Model Class - One of the models just built using the ADO.NEt Entity Data Model Data Context Class **Do not choose the same model from above select the option with Database+Entities name

From here I was able to call a url;


This successfully brought back data from my database.

10/25/2013 7:07:20 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow