创建控制器时不支持的上下文类型
本文关键字:上下文 类型 不支持 控制器 创建 | 更新日期: 2023-09-27 18:36:58
.net新手,不确定我在这里做错了什么。我创建了一个 c# 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 控制器,使用实体框架
以下是我用于创建简单 MVC API 应用程序的步骤
- 打开 Visual Studio 2012 并创建一个 ASP.NET MVC v4 应用程序
- 选择接口
- 在解决方案资源管理器中找到模型目录,然后右键单击并选择"添加">"新项"
- 从"添加新项"中找到 ADO.Net 实体数据模型5 .通过向导 ADO.NET 它将允许您生成与SQL Server的连接
- 选择要为其构建模型的表
- 模型装箱后,右键单击"控制器"并选择添加>控制器
- 选择模板 -"具有读/写操作的 API 控制器,使用实体框架" 模型类 - 刚刚使用 ADO.NEt 实体数据模型生成的模型之一 数据上下文类 **不要从上面选择相同的模型,选择具有"数据库+实体名称"的选项
从这里我可以调用一个网址;
www.application.com/api/TestController/?id=1
这成功地从我的数据库中带回了数据。