0

.net 的新手不确定我在这里做错了什么。我创建了 ac# API 项目,然后使用了 ADO.Net 实体映射。看起来它根据我的所有表为模型创建了正确的 .cs 文件。我想下一步是创建一个控制器,但是当发生这种情况时我会收到一条错误消息。

模型 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; }
    }
}

当我将此模型设置为模型类和数据上下文类时收到的错误消息是

Unsupported Context Type 

我使用的模板是具有读/写操作的 API 控制器,使用实体框架

4

1 回答 1

3

以下是我用来创建简单 MVC API 应用程序的步骤

  1. 打开 Visual Studio 2012 并创建一个 ASP.NET MVC v4 应用程序
  2. 选择 API
  3. 在解决方案资源管理器位置中,模型目录并右键单击并选择“添加”>“新项目”
  4. 从“添加新项目”中找到 ADO.Net Entity Data Model 5 。通过 ADO.NET 向导,您可以生成与 SQL Server 的连接
  5. 选择您要为其构建模型的表
  6. 创建模型后,右键单击“控制器”并选择“添加”>“控制器”
  7. 选择模板 - 'API 控制器具有读/写操作,使用实体框架' 模型类 - 刚刚使用 ADO.NEt 实体数据模型数据上下文类构建的模型之一* *不要从上面选择相同的模型选择带有的选项数据库+实体名称

从这里我可以调用一个网址;

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

这成功地从我的数据库中带回了数据。

于 2013-10-25T19:07:20.063 回答