精进不休 .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 ...
随机推荐
- Mac 下配置 SSH 免密码安全登录
Win下个人常使用 SecureCRT ,Mac 下感觉 SecureCRT 并不好使,常用 iTerm2+zsh 搭配使用.A连接B 无密码登陆,则A上面执行 ssh-keygen 一路回车,把 ~ ...
- mvc 返回 xml
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...
- Openvswitch原理与代码分析(3): openvswitch内核模块的加载
上一节我们讲了ovs-vswitchd,其中虚拟网桥初始化的时候,对调用内核模块来添加虚拟网卡. 我们从openvswitch内核模块的加载过程,来看这个过程. 在datapath/dat ...
- mysql用shell建100多字段表并导入
excel列超过160多个,导入时报错,把excel第一行另存为逗号分隔的csv文件,用shell建表 vim createTable.sh #!/bin/sh str="CA6430M,H ...
- android 九宫加密记事本
自己写的超级安全记事本,用PBEWithMD5AndDES加密sqlite内容几乎无法破解, 九宫点密码登录, 支持备份到SDcard,email,network drivers etc. 附件Apk ...
- Eclipse:Cannot complete the install because of a conflicting dependency.问题解决
今天尝试在线更新ADT(22到23)的时候,遇到了这么个问题,从错误提示中初步看起来是存在引用的冲突: 估计大家在把22升级到23的时候都会遇上这个问题,新旧版冲突,感觉像是ADT自己的bug. 其实 ...
- 修改mysql默认字符集的方法
+--------------------------+---------------------------------+ | Variable_name | Value | +---------- ...
- C#简易播放器(基于开源VLC)
可见光通信技术(Visible Light Communication,VLC)是指利用可见光波段的光作为信息载体,不使用光纤等有线信道的传输介质,而在空气中直接传输光信号的通信方式.LED可见光通信 ...
- HTML5[3]:中文换行
保证中文每行第一个字,不会出现标点符号 p { white-space: pre-wrap; }
- .NET中TextBox控件设置ReadOnly=true后台取不到值的解决方法
在.NET 2.0 下,当页面上的某个TextBox 设置了属性ReadOnly="True"时,通过客户端脚本给其赋值后,在后台代码中访问其Text属性却无法获得该值.经过尝试, ...