精进不休 .NET 4.5 (12) - ADO.NET Entity Framework 6.0 新特性, WCF Data Services 5.6 新特性
作者:webabcd
介绍
精进不休 .NET 4.5
- ADO.NET Entity Framework 6.0 新特性
- WCF Data Services 5.6 新特性
示例
1、演示 ADO.NET Entity Framework 6.0 的新特性 - 对 async await 的支持
EF6.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EF6.aspx.cs" Inherits="EF60_DS56.EF6" Async="true" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div> </div>
</form>
</body>
</html>
EF6.aspx.cs
/*
* 演示 ADO.NET Entity Framework 6.0 的新特性 - 对 async await 的支持
*/ using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; using EF60_DS56.Model;
using System.Data.Entity; // 注意:必须要引用此命名空间,它包含了诸如 FirstAsync() ToListAsync() 等异步的扩展方法
using System.Threading.Tasks; namespace EF60_DS56
{
public partial class EF6 : System.Web.UI.Page
{
// 注意:必须在页头中增加 <%@ Async="true" %> 以支持异步
protected async void Page_Load(object sender, EventArgs e)
{
await AsyncDemo1();
await AsyncDemo2();
} public async Task AsyncDemo1()
{
NorthwindEntities context = new NorthwindEntities();
var product = await context.Products.FirstAsync(); // 此类异步查询扩展方法来自 System.Data.Entity 命名空间
product.ProductName = "webabcd " + DateTime.Now.ToString("mm:ss"); await context.SaveChangesAsync();
} public async Task AsyncDemo2()
{
NorthwindEntities context = new NorthwindEntities();
var product = await context.Products.FirstOrDefaultAsync(); // 此类异步查询扩展方法来自 System.Data.Entity 命名空间 Response.Write(product.ProductName);
}
}
}
2、演示 WCF Data Services 5.6 的新特性 - 对 ADO.NET Entity Framework 6.0 的支持
WcfDataService.svc.cs
/*
* 演示 WCF Data Services 5.6 的新特性 - 对 ADO.NET Entity Framework 6.0 的支持
*/ using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel.Web;
using System.Web; namespace EF60_DS56
{
// DataService<T> - ef5 或以下版本
// public class WcfDataService : DataService<EF60_DS56.Model.NorthwindEntities> // EntityFrameworkDataService<T> - ef6 或以上版本
// 注意:在“Install-Package Microsoft.OData.EntityFrameworkProvider -Pre”之后才会有 EntityFrameworkDataService<T>
public class WcfDataService : System.Data.Services.Providers.EntityFrameworkDataService<EF60_DS56.Model.NorthwindEntities>
{
public static void InitializeService(DataServiceConfiguration config)
{
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
}
}
}
3、其他
Index.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>精进不休 .NET 4.5 - ADO.NET Entity Framework 6.0 新特性, WCF Data Services 5.6 新特性</title>
</head>
<body>
<h2>精进不休 .NET 4.5 - ADO.NET Entity Framework 6.0 新特性, WCF Data Services 5.6 新特性</h2> <p>
<a href="EF6.aspx" target="_blank">
ADO.NET Entity Framework 6.0 新特性 - 支持 async await (示例代码参见:EF6.aspx.cs)
</a>
</p> <p>
<a href="WcfDataService.svc/Products()?$top=1" target="_blank">
WCF Data Services 5.6 新特性 - 支持 EF6 (示例代码参见:WcfDataService.svc.cs)
</a>
</p> <p>
注:请在 nuget 中搜索 entity framework 6 安装 ef6
</p> <p>
注:让 ds5.6 支持 ef6 需要用到 EntityFrameworkDataService,可以通过 nuget 控制台(工具 -> 库程序包管理器 -> 程序包管理器控制台)安装 Install-Package Microsoft.OData.EntityFrameworkProvider -Pre
</p>
</body>
</html>
OK
[源码下载]
精进不休 .NET 4.5 (12) - ADO.NET Entity Framework 6.0 新特性, WCF Data Services 5.6 新特性的更多相关文章
- 在Entity Framework 4.0中使用 Repository 和 Unit of Work 模式
[原文地址]Using Repository and Unit of Work patterns with Entity Framework 4.0 [原文发表日期] 16 June 09 04:08 ...
- ADO.NET-EF:ADO.NET Entity Framework 百科
ylbtech-ADO.NET-EF:ADO.NET Entity Framework 百科 ADO.NET Entity Framework 是微软以 ADO.NET 为基础所发展出来的对象关系对应 ...
- ADO.NET Entity Framework CodeFirst 如何输出日志(EF 5.0)
ADO.NET Entity Framework CodeFirst 如何输出日志(EF4.3) 用的EFProviderWrappers ,这个组件好久没有更新了,对于SQL执行日志的解决方案的需求 ...
- 如何得到EF(ADO.NET Entity Framework)查询生成的SQL? ToTraceString Database.Log
ADO.NET Entity Framework ToTraceString //输出单条查询 DbContext.Database.Log //这里有详细的日志
- ADO.NET Entity Framework
ADO.NET Entity Framework 是微软以 ADO.NET 为基础所发展出来的对象关系对应 (O/R Mapping) 解决方案, 早期被称为 ObjectSpace,现已经包含在 V ...
- Microsoft SQL Server Compact 4.0&&ADO.NET Entity Framework 4.1&&MVC3
最近重新查看微软MvcMusicStore-v3.0的源代码,发现忽略了很多重要的东西,特别是数据访问那一部分. 首先Microsoft SQL Server Compact 4.0 详细的介绍和下载 ...
- ADO.NET Entity Framework(EF)
ylbtech-Miscellaneos: ADO.NET Entity Framework(EF) A,返回顶部 1, ADO.NET Entity Framework 是微软以 ADO.NET 为 ...
- 读书笔记之ado.net entity framework
提供了对数据访问的一种抽象层,是更加易于以编程的方式来操作及管理数据 有以下几种模式:Model First, Database First, and Code First 现在主要讨论code Fi ...
- 让ADO.NET Entity Framework支持Oracle数据库
Oracle最近发布了 Oracle Data Access Component(ODAC)11. 2 Rel 4,其中增加了对 Entity Framework 4.1 和4.2的支持.这让 .NE ...
随机推荐
- 解决URL路径包含+等特殊符号,编码也无效的办法
<?xml version="1.0" encoding="UTF-8"?><configuration> <syste ...
- PHP读写文件高并发处理实例-转
背景: 最近公司游戏开发需要知道游戏加载的流失率.因为,我们做的是网页游戏.玩过网页游戏的人都知道,进入游戏前要加载一些资源.最后才能到达创建角色的游戏界面.我们有一个需求就是要统计在加载过程中还未到 ...
- MD5 加密的两种方法
System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5Cryp ...
- JS - IE中没有console定义
由于IE中没有Console相关定义,所以不能使用它输出打印信息,且会出现脚本中断. 所以在IE中务必去掉(注释掉)console相关脚本代码.
- Mac OSX 安装nvm(node.js版本管理器)
我的系统 1.打开github官网https://github.com/,输入nvm搜索,选择creationix/nvm,打开 2.找到Install script,复制 curl -o- http ...
- android中的提示信息显示方法(toast应用)
android中的提示信息显示方法(toast应用) (2011-10-17 11:02:06) 转载▼ 标签: android toast 杂谈 分类: Android android中toast的 ...
- android html 与webview属性从冲突
在最近的项目开发中,使用webview加载html页面,这样可以节省大量页面开发的时间,同时也可加快项目进度. 我们需求是需要显示商品评论,页面设计如下: 调用android代码,对于webview的 ...
- (转)关于tcp和udp的缓冲区
(一)基础知识 IPv4 数据报最大大小是65535(16位),包括IPv4头部. IPv6 数据报最大大小是65575,包括40个字节的IPv4头部 MTU,这是由硬件规定的,如以太网的MTU是15 ...
- UITableViewCell分割线左边部分缺少一些的解决方法
-(void)viewDidLayoutSubviews { if ([self.mytableview respondsToSelector:@selector(setSeparato ...
- CentOS7之VMware安装
选择CentOS的原因 起初也了解了几个linux的发行版,最终决定选择centOS的原因却很简单:阿里云和腾讯云提供的云服务器中centos的版本最多. VMware12的安装 下载地址:http ...