• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >ASP.NET > ASP.NET Web API教程 创建Admin控制器实例分享

ASP.NET Web API教程 创建Admin控制器实例分享

作者: 字体:[增加 减小] 来源:互联网 时间:2017-05-11

通过本文主要向大家介绍了精通asp.net web api,web程序设计asp.net,vs2010 asp.net web,简述asp.net的web窗体,asp.net等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
In this section, we'll add a Web API controller that supports CRUD (create, read, update, and delete) operations on products. The controller will use Entity Framework to communicate with the database layer. Only administrators will be able to use this controller. Customers will access the products through another controller.
在本小节中,我们要添加一个对产品支持CRUD(创建、读取、更新和删除)操作的Web API控制器。该控制器将使用实体框架与数据库层进行通信。只有管理员才能够使用这个控制器。客户端将通过另一个控制器访问产品。
In Solution Explorer, right-click the Controllers folder. Select Add and then Controller.
在“解决方案资源管理器”中右击Controllers文件夹,选择“添加”,然后选“控制器”(见图2-16)。
WebAPI2-16 
图2-16. 添加控制器
In the Add Controller dialog, name the controller AdminController. Under Template, select "API controller with read/write actions, using Entity Framework". Under Model class, select "Product (ProductStore.Models)". Under Data Context, select "<New Data Context>".
在“添加控制器”对话框中,将此控制器命名为AdminController。在“模板”下选择“带有读/写动作的API控制器(用实体框架)”。在“模型类”下选择“Product (ProductStore.Models)”。在“数据上下文”下选择“<新数据上下文>”(见图2-17)。
WebAPI2-17 
图2-17. 添加控制器对话框中的设置
If the Model class drop-down does not show any model classes, make sure you compiled the project. Entity Framework uses reflection, so it needs the compiled assembly.
如果“模型类”下拉列表未显示任何模型类,请确保已编译了此项目。实体框架使用反射,因此它需要已编译的程序集。
Selecting "<New Data Context>" will open the New Data Context dialog. Name the data context ProductStore.Models.OrdersContext.
选择“<新数据上下文>”会打开“新数据上下文”对话框。将该数据上下文命名为ProductStore.Models.OrdersContext(见图2-18)。
WebAPI2-18 
图2-18. 命名“新数据上下文”
Click OK to dismiss the New Data Context dialog. In the Add Controller dialog, click Add.
点击“OK”退出这个“新数据上下文”对话框。在“添加控制器”对话框中点击“添加”。
Here's what got added to the project:
以下是添加到项目的内容:
A class named OrdersContext that derives from DbContext. This class provides the glue between the POCO models and the database.
一个名称为的OrdersContext类,它派生于DbContext。这个类提供了POCO模型与数据库之间的粘合。
A Web API controller named AdminController. This controller supports CRUD operations on Product instances. It uses the OrdersContext class to communicate with Entity Framework.
一个名称为AdminController的Web API控制器。这个控制器支持对Product实例的CRUD操作。它使用OrdersContext类与实体框架进行通信。
A new database connection string in the Web.config file.
Web.config文件中的一个新的数据库连接字符串。
上述新添加项见图2-19。
WebAPI2-19 
图2-19. 新添加到项目的内容
Open the OrdersContext.cs file. Notice that the constructor specifies the name of the database connection string. This name refers to the connection string that was added to Web.config.
打开OrdersContext.cs文件。注意,其构造器指明了数据库连接字符串的名称。该名称是指被添加到Web.config的连接字符串。
By inheriting from the DropCreat
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • ASP.NET core Web中使用appsettings.json配置文件的方法
  • 详解ASP.NET WEB API 之属性路由
  • ASP.NET webUploader上传大视频文件相关web.config配置
  • asp.net web页面自定义分页控件使用详解
  • ASP.NET Web.config配置文件详解
  • ASP.NET web.config 配置节点详解
  • ASP.NET Web Api 2实现多文件打包并下载文件的实例
  • ASP.NET web.config中 数据库连接字符串加密解密
  • 在ASP.NET 2.0中操作数据之五十三:在Data Web控件显示二进制数据
  • asp.net基于Web Service实现远程上传图片的方法

相关文章

  • 2017-05-11一步步做自己的webinstall安装包
  • 2018-08-20.net core下对于附件上传下载的实现示例
  • 2017-05-11"虚拟路径"..."映射到另一个应用程序,这是不允许的!
  • 2017-05-11Asp.net操作Excel更轻松的实现代码
  • 2017-05-11asp.net 处理F5刷新页面重复提交页面的一个思路
  • 2017-05-11Asp.Net 重定向必须要知道的一些资料
  • 2017-05-11asp.net javascript 文件无刷新上传实例代码第1/2页
  • 2017-05-11.NET中的属性用法分析
  • 2017-05-11查看Json输出的*最方便*的方法 (转)
  • 2017-05-11asp.net jquery无刷新分页插件(jquery.pagination.js)

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • 用扩展方法优化多条件查询(不定条件查询)
    • asp.net后台如何动态添加JS文件和css文件的引用
    • asp.net TripleDES加密、解密算法
    • asp.net获取网站目录物理路径示例
    • 在Global.asax文件里实现通用防SQL注入漏洞程序(适应于post/get请求)
    • ASP.NET(C#)读取Excel的文件内容
    • asp.net 判断数组是否存在某个值的方法
    • C# 生转换网页为pdf
    • Visual Studio 2017正式版发布 Mac版新功能特性有哪些
    • 得到真实外网IP、IP所在国家、省份、地区(小偷程序)

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有