通过本文主要向大家介绍了精通asp.net web api,web程序设计asp.net,vs2010 asp.net web,简述asp.net的web窗体,asp.net等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
添加模型
There are three ways to approach Entity Framework:
有三种方式使用实体框架:
Database-first: You start with a database, and Entity Framework generates the code.
Database-first(数据库先行):从一个数据库开始,然后实体框架生成相应代码。
Model-first: You start with a visual model, and Entity Framework generates both the database and code.
Model-first(模型先行):先从一个可视化模型开始,然后实体框架生成数据库和代码。
Code-first: You start with code, and Entity Framework generates the database.
Code-first(代码先行):先从代码开始,然后实体框架生成数据库。
We are using the code-first approach, so we start by defining our domain objects as POCOs (plain-old CLR objects). With the code-first approach, domain objects don't need any extra code to support the database layer, such as transactions or persistence. (Specifically, they do not need to inherit from the EntityObject class.) You can still use data annotations to control how Entity Framework creates the database schema.
我们打算使用code-first方法,因此,首先把域对象定义成POCO(plain-old CLR objects — 旧式无格式公共语言运行时(CLR)对象。很多人不太理解POCO对象,其实这种对象就像文本文件一样,是一种最简单、最原始、不带任何格式的对象。因此,在各种环境中最容易对这类对象进行处理,包括用各类语言进行处理 — 译者注)。利用code-first方法,域对象不需要任何附加代码去支持数据库层,如事务处理、持久化等。(特别是它们不需要继承于EntityObject类。)你仍可以使用数据注解(data annotation)对实体框架如何创建数据库方案进行控制。
Because POCOs do not carry any extra properties that describe database state, they can easily be serialized to JSON or XML. However, that does not mean you should always expose your Entity Framework models directly to clients, as we'll see later in the tutorial.
由于POCO不带描述数据库状态的任何附加属性,它们可以很容易地被序列化成JSON或XML。然而,这并不意味着你应当总是把实体框架模型直接暴露给客户端,就像我们稍后在本教程所看到的那样。
We will create the following POCOs:
我们将创建以下POCO:
Product
Order
OrderDetail
To create each class, right-click the Models folder in Solution Explorer. From the context menu, select Add and then select Class.
要创建每个类,在“解决方案资源管理器”中右击Models文件夹。从上下文菜单选择“添加”,然后选择“类”(如图2-14所示)。
图2-14. 创建POCO类
Add a Product class with the following implementation:
用以下实现添加一个Product类(产品类):
In Solution Explorer, expand the App_Start folder and open the file named WebApiConfig.cs. Add the following cod
There are three ways to approach Entity Framework:
有三种方式使用实体框架:
Database-first: You start with a database, and Entity Framework generates the code.
Database-first(数据库先行):从一个数据库开始,然后实体框架生成相应代码。
Model-first: You start with a visual model, and Entity Framework generates both the database and code.
Model-first(模型先行):先从一个可视化模型开始,然后实体框架生成数据库和代码。
Code-first: You start with code, and Entity Framework generates the database.
Code-first(代码先行):先从代码开始,然后实体框架生成数据库。
We are using the code-first approach, so we start by defining our domain objects as POCOs (plain-old CLR objects). With the code-first approach, domain objects don't need any extra code to support the database layer, such as transactions or persistence. (Specifically, they do not need to inherit from the EntityObject class.) You can still use data annotations to control how Entity Framework creates the database schema.
我们打算使用code-first方法,因此,首先把域对象定义成POCO(plain-old CLR objects — 旧式无格式公共语言运行时(CLR)对象。很多人不太理解POCO对象,其实这种对象就像文本文件一样,是一种最简单、最原始、不带任何格式的对象。因此,在各种环境中最容易对这类对象进行处理,包括用各类语言进行处理 — 译者注)。利用code-first方法,域对象不需要任何附加代码去支持数据库层,如事务处理、持久化等。(特别是它们不需要继承于EntityObject类。)你仍可以使用数据注解(data annotation)对实体框架如何创建数据库方案进行控制。
Because POCOs do not carry any extra properties that describe database state, they can easily be serialized to JSON or XML. However, that does not mean you should always expose your Entity Framework models directly to clients, as we'll see later in the tutorial.
由于POCO不带描述数据库状态的任何附加属性,它们可以很容易地被序列化成JSON或XML。然而,这并不意味着你应当总是把实体框架模型直接暴露给客户端,就像我们稍后在本教程所看到的那样。
We will create the following POCOs:
我们将创建以下POCO:
Product
Order
OrderDetail
To create each class, right-click the Models folder in Solution Explorer. From the context menu, select Add and then select Class.
要创建每个类,在“解决方案资源管理器”中右击Models文件夹。从上下文菜单选择“添加”,然后选择“类”(如图2-14所示)。

图2-14. 创建POCO类
Add a Product class with the following implementation:
用以下实现添加一个Product类(产品类):
In Solution Explorer, expand the App_Start folder and open the file named WebApiConfig.cs. Add the following cod
您可能想查找下面的文章:
- 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实现远程上传图片的方法