精进不休 .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 ...
随机推荐
- Multiple Contexts have a path of "/xxxx"问题解决
转自:http://blog.csdn.net/ivanzhangqf/article/details/50326533 之前因为ecplise项目保存更新时一直显示等待后台操作完成,以至于一直卡住无 ...
- 单线程vs多线程
a.多线程可以说是实现异步的一种方式: b.共同点:多线程和异步操作两者都可以达到避免调用线程阻塞的目的,从而提高软件的可响应性: c.线程消费CPU资源. 异步消费硬件资源: 1.多线程和异步操作 ...
- mysql DB server端,如何让读写更快
其实,我不是专业的DB管理同学,甚至算不上会了解.只是在最近的工作中,遇到了DB server端优化的契机,所以把这些手段记录下来: 通过调整这个参数的值,可以让DB更给力: 这两个参数的含义: 1. ...
- 【Xamarin报错】 COMPILETODALVIK : UNEXPECTED TOP-LEVEL error java.lang.OutOfMemoryError: Java heap space
Xamarin Android 编译报错: COMPILETODALVIK : UNEXPECTED TOP-LEVEL error java.lang.OutOfMemoryError: Java ...
- 再探 Ext JS 6 (sencha touch/ext升级版) 变化篇 (编译命令、滚动条、控制层、模型层、路由)
从sencha touch 2.4.2升级到ext js 6,cmd版本升级到6.0之后发生了很多变化 首先从cmd说起,cmd 6 中sencha app build package不能使用了,se ...
- Android开发艺术探索笔记—— View(一)
Android开发艺术探索笔记 --View(一) View的基础知识 什么是View View是Android中所有控件的基类.是一种界面层控件的抽象. View的位置参数 参数名 获取方式 含义 ...
- react-native SyntaxError xxxxx/xx.js:Unexpected token (23:24)
在运行react-native项目时提示 SyntaxError xxxxx/xx.js:Unexpected token (23:24) 我这边的问题原因:jsx语法错误,解决办法就是认真排查代码然 ...
- __proto__与prototype
值得一说的是对象没有prototype属性,只有函数有prototype属性. var a = function(){}; a.prototype.d = function(){ console.lo ...
- MongoDB入门二:基本概念
前言 工欲善其事必先利其器.在学习MongoDB之前,需要对MongoDB的一些基本概念有系统的了解. 所以,本篇文章主要介绍MongoDB的一些基本概念,这些概念的定义均来自<MongoDB权 ...
- 前端们,gulp该用起来了,简单的demo入门——gulp系列(一)
gulp.grunt前端自动化工具,只有用过才知道多么重要. 它们问世这么久了?你真的用过吗? 写个简单的less.watch任务的demo分享———— 1.准备: 安装全局node.npm,这个教程 ...