0

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

2
  • nevermind. If I set the proper data context everything worked. wow this MVC stuff is very powerful.. Commented Oct 25, 2013 at 18:46
  • 1
    Please add that as an answer and then accept it when you can. Commented Oct 25, 2013 at 18:56

1 Answer 1

3

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;

www.application.com/api/TestController/?id=1

This successfully brought back data from my database.

Sign up to request clarification or add additional context in comments.

1 Comment

The key is to make sure you select YOURDATABASENAMEEntities as the "Data context class"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.