精进不休 .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 ...
随机推荐
- Firefox终于返回到了Debian stable
6月8日,firefox 45.2以安全修复包的名义回到了Debian oldstable (即wheezy),两天以后,Debian 8 jessie里面也有了(https://packages.d ...
- dede教程之后台登录是自动跳出解决方法
有时也不知道什么原因,登录后台时输入全部正确点确认按钮时却会自动跳出.必须输入http://你的域名/dede/login.php才可以登录.通过尝试最终解决了问题,下面分享出来: 1.打开根目录da ...
- php 生成 Json
php 生成 Json 部分 <?php $arr_result = array(); //返回值 $arr_result['result'] = '0'; $arr_result['calle ...
- Swift 正式开源, 包括 Swift 核心库和包管理器
Swift 正式开源!Swift 团队很高兴宣布 Swift 开始开源新篇章.自从苹果发布 Swfit 编程语言,就成为了历史上发展最快的编程语言之一.Swift 通过设计使得软件编写更加快速更加安全 ...
- visual studio 2013使用技巧
去掉 引用提示 文本编辑器=>所有语言=>codelens visual studio 由于以前的函数求值超时,函数求值被禁用.必须继续执行才能重新启用函数求值 visual studio ...
- 用C#制作PDF文件全攻略
用C#制作PDF文件全攻略 目 录 前 言... 3 第一部分 iText的简单应用... 4 第一章 创建一个Document 4 第一步 创建一个Document实例:... 5 第二步 ...
- java之对象转型2
public class TestCasting2{ public static void main(String args[]){ TestCasting2 test2= new TestCasti ...
- 各种字符串Hash函数比较(转)
常用的字符串Hash函数还有ELFHash,APHash等等,都是十分简单有效的方法.这些函数使用位运算使得每一个字符都对最后的函数值产生影响.另外还有以MD5和SHA1为代表的杂凑函数,这些函数几乎 ...
- netty 编/解码处理
1.LineBasedFrameDecoder 1.先找到结束符索引 private static int findEndOfLine(final ByteBuf buffer) { final in ...
- 2014-09-19.xml
<wordbook><item> <word>basel</word> <trans><![CDATA[ n. 巴塞尔( ...