再接再厉VS 2008 sp1 + .NET 3.5 sp1(5) - Entity Framework(实体框架)之ObjectContext
[索引页]
[源码下载]
作者:webabcd
介绍
以Northwind为示例数据库,ADO.NET Entity Framework之详解ObjectContext, 以及事务和并发
示例
1、详解ObjectContext
ObjectContext.aspx
<%@ Page Title="ObjectContext" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="ObjectContext.aspx.cs" Inherits="EntityFramework_ObjectContext" %>
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<div id="result" runat="server" />
</asp:Content>
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
ObjectContext.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Data;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
using VS2008SP1.Business;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
public partial class EntityFramework_ObjectContext : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Demo();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
result.InnerHtml += "<br />";
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Demo2();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
result.InnerHtml += "<br />";
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Demo3();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
result.InnerHtml += "<br />";
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Demo4();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
result.InnerHtml += "<br />";
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Demo5();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
result.InnerHtml += "<br />";
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Demo6();
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void Demo()
{
// ObjectContext - 以对象(这些对象是 EDM 中定义的实体类型的实例)的形式与数据进行交互
using (var ctx = new NorthwindEntities())
{
// CreateObjectName - 实体类 的 CreateObjectName 静态方法用于创建实体类的新实例
Region region = Region.CreateRegion("RegionDescription", 100);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// System.Data.EntityState - 实体状态
// System.Data.EntityState.Detached - 被分离
// System.Data.EntityState.Unchanged - 未发生变化
// System.Data.EntityState.Added - 被增加
// System.Data.EntityState.Deleted - 被删除
// System.Data.EntityState.Modified - 被修改
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
result.InnerHtml += region.EntityState + "<br />"; // Detached
// AddToEntitySetName() - 将需要添加的对象添加到对象上下文中
// AddObject(string entitySetName, object entity) - 将需要添加的对象添加到对象上下文中
// ctx.AddObject("Region", region);
ctx.AddToRegion(region);
result.InnerHtml += region.EntityState + "<br />"; // Added
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// SaveChanges() - 将所有更新保存到相关存储区中。将所有实体的 EntityState 标记为 EntityState.Unchanged
// SaveChanges(bool acceptChangesDuringSave) - acceptChangesDuringSave 指定是否将所有实体的 EntityState 标记为 EntityState.Unchanged 。 如果指定为 false 则不会修改实体的 EntityState
ctx.SaveChanges();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
result.InnerHtml += region.EntityState + "<br />"; // Unchanged
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void Demo2()
{
using (var ctx = new NorthwindEntities())
{
Region region = ctx.Region.First(p => p.RegionID == 100);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
result.InnerHtml += region.EntityState + "<br />"; // Unchanged
region.RegionDescription = "RegionDescriptionUpdated";
result.InnerHtml += region.EntityState + "<br />"; // Modified
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
ctx.SaveChanges(false);
// ObjectStateEntry - 维护实体状态的类
// GetModifiedProperties() - 获取被修改的属性。返回值 IEnumerable<string>
// ObjectStateManager - 实体状态管理器
// GetObjectStateEntry()/TryGetObjectStateEntry() - 获取指定实体的 ObjectStateEntry
// GetObjectStateEntries(EntityState state) - 获取所指定状态的 ObjectStateEntry 集合。返回值 IEnumerable<ObjectStateEntry>
// ObjectStateManagerChanged事件 - 将实体添加到 ObjectStateManager 中或从中移除实体时发生
ObjectStateEntry ose = ctx.ObjectStateManager.GetObjectStateEntry(region);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// ObjectStateEntry.State - 实体状态
// ObjectStateEntry.OriginalValues - 原始值
// ObjectStateEntry.CurrentValues - 当前值
result.InnerHtml += ose.State + "<br />"; // Modified (region.EntityState)
result.InnerHtml += ose.OriginalValues["RegionDescription"] + "<br />"; // RegionDescription
result.InnerHtml += ose.CurrentValues["RegionDescription"] + "<br />"; // RegionDescriptionUpdated
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// ObjectStateEntry.AcceptChanges()/ObjectContext.AcceptAllChanges() - 将相关的实体状态置为 EntityState.Unchanged
ose.AcceptChanges();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
result.InnerHtml += ose.State + "<br />"; // Unchanged
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void Demo3()
{
using (var ctx = new NorthwindEntities())
{
// 加载指定的 Region 到上下文中
Region regionRead = ctx.Region.First(p => p.RegionID == 100);
// 创建一个需要更新的 Region
Region regionUpdate = Region.CreateRegion("RegionDescriptionUpdatedSecond", 100);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
result.InnerHtml += regionRead.EntityState + "<br />"; // Unchanged
result.InnerHtml += regionUpdate.EntityState + "<br />"; // Detached
// ApplyPropertyChanges(string entitySetName, object changed) - 更新指定的实体(其所对应的主键实体需要加载到上下文中)
ctx.ApplyPropertyChanges("Region", regionUpdate);
result.InnerHtml += regionRead.EntityState + "<br />"; // Modified
result.InnerHtml += regionUpdate.EntityState + "<br />"; // Detached
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
ctx.SaveChanges();
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void Demo4()
{
using (var ctx = new NorthwindEntities())
{
Region region = new Region() { RegionID = 100, RegionDescription = "RegionDescriptionUpdatedThird" };
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
result.InnerHtml += region.EntityState + "<br />"; // Detached
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// Attach()/AttachTo() - 附加外部实体到上下文中
// ctx.Attach(region);
ctx.AttachTo("Region", region);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
ObjectStateEntry ose = ctx.ObjectStateManager.GetObjectStateEntry(region);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// SetModified() - 标记实体状态为 EntityState.Modified
// SetModifiedProperty() - 标记需要修改的属性,从而完成对指定属性的修改
ose.SetModifiedProperty("RegionDescription");
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// 以当前数据为准更新存储模型
ctx.Refresh(RefreshMode.ClientWins, region);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
result.InnerHtml += region.EntityState + "<br />"; // Modified
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
ctx.SaveChanges();
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void Demo5()
{
using (var ctx = new NorthwindEntities())
{
Region region = new Region() { RegionID = 100 };
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// CreateEntityKey(string entitySetName, object entity) - 创建 EntityKey
EntityKey ek = ctx.CreateEntityKey("Region", region);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// ObjectContext.GetObjectByKey()/TryGetObjectByKey() - 根据指定的 EntityKey 获取实体
Region r = ctx.GetObjectByKey(ek) as Region;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
ctx.SaveChanges();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
result.InnerHtml += r.RegionDescription + "<br />"; // RegionDescriptionUpdatedThird
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void Demo6()
{
using (var ctx = new NorthwindEntities())
{
Region region = ctx.Region.First(p => p.RegionID == 100);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
result.InnerHtml += region.EntityState + "<br />"; // Unchanged
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// ObjectStateEntry.Delete() - 标记实体的状态为删除。同 DeleteObject()
ObjectStateEntry ose = ctx.ObjectStateManager.GetObjectStateEntry(region);
ose.Delete();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// DeleteObject() - 删除实体
// ctx.DeleteObject(region);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
result.InnerHtml += region.EntityState + "<br />"; // Deleted
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
ctx.SaveChanges();
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2、事务和并发处理
ObjectContext2.aspx
<%@ Page Title="事务和并发处理" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="ObjectContext2.aspx.cs" Inherits="EntityFramework_ObjectContext2" %>
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<div id="result" runat="server" />
</asp:Content>
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
ObjectContext2.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Data;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
using VS2008SP1.Business;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
public partial class EntityFramework_ObjectContext2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// 演示事务的 Demo
Demo();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
result.InnerHtml += "<br />";
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// 演示并发的 Demo
Demo2();
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void Demo()
{
// ObjectContext - SaveChanges 中的逻辑会自动做事务处理
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// 通吃的事务处理
// using (System.Transactions.TransactionScope tc = new TransactionScope())
// {
// code
// tc.Complete();
// }
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// 同一 ObjectContext 的多个 SaveChanges() 的事务处理
using (var ctx = new NorthwindEntities())
{
Region region = Region.CreateRegion("Test", 101);
ctx.AddToRegion(region);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (ctx.Connection.State != ConnectionState.Open)
{
ctx.Connection.Open();
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// 开始一个事务
System.Data.Common.DbTransaction tran = ctx.Connection.BeginTransaction();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// 第一次对数据的操作
ctx.SaveChanges();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
try
{
Region region2 = Region.CreateRegion("Test2", 101);
ctx.AddToRegion(region2);
// 第二次对数据库的操作
ctx.SaveChanges();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// 提交事务(第一次插入主键为 101 的记录,成功;第二次再次插入主键为 101 的记录,失败。所以此处会报错)
tran.Commit();
}
catch (Exception)
{
result.InnerHtml += "回滚" + "<br />";
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// 回滚事务(第一次插入成功的主键为 101 的记录会被删除)
tran.Rollback();
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void Demo2()
{
var ctx = new NorthwindEntities();
var ctx2 = new NorthwindEntities();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
var region = ctx.Region.First();
var region2 = ctx2.Region.First();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// 需要做并发处理的字段,要将其“并发模式”属性设置为 Fixed
region.RegionDescription = "Eastern" + Guid.NewGuid().ToString();
region2.RegionDescription = "Eastern" + Guid.NewGuid().ToString();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
ctx.SaveChanges();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
try
{
// ctx 已经修改了 Region 的 RegionDescription 属性
// ctx2 再次修改 Region 的 RegionDescription 属性,由于 RegionDescription 在 ctx2 读取之后发生了变化,所以会出现乐观并发(Optimistic Concurrency)问题
ctx2.SaveChanges();
}
catch (System.Data.OptimisticConcurrencyException)
{
result.InnerHtml += "OptimisticConcurrencyException" + "<br />";
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// ObjectContext.Refresh(RefreshMode refreshMode, object entity) - 更新上下文数据
// RefreshMode.StoreWins - 以数据库中的值为准
// RefreshMode.ClientWins - 以当前数据为准
// object entity - 需要刷新上下文数据的实体
ctx2.Refresh(RefreshMode.StoreWins, region2);
// ctx2.Refresh(RefreshMode.ClientWins, region2);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
ctx2.SaveChanges();
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// 可以不通过 try catch 处理并发,而是通过 Refresh() 直接处理更新逻辑
// 即若是 RefreshMode.ClientWins 则永远以当前值为准;若是 RefreshMode.StoreWins 则永远以数据库中的值为准(不会更新数据)
// ctx2.Refresh(RefreshMode.StoreWins, region2);
// ctx2.SaveChanges();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
ctx.Dispose();
ctx2.Dispose();
}
}
OK
[源码下载]
[源码下载]
再接再厉VS 2008 sp1 + .NET 3.5 sp1(5) - Entity Framework(实体框架)之ObjectContext
作者:webabcd
介绍
以Northwind为示例数据库,ADO.NET Entity Framework之详解ObjectContext, 以及事务和并发
- ObjectContext - 以对象(这些对象是 EDM 中定义的实体类型的实例)的形式与数据进行交互
- CreateObjectName - 实体类 的 CreateObjectName 静态方法用于创建实体类的新实例
- AddToEntitySetName() - 将需要添加的对象添加到对象上下文中
- SaveChanges() - 将所有更新保存到相关存储区中
- Attach()/AttachTo() - 附加外部实体到上下文中
- ObjectContext.Refresh() - 更新上下文数据
- ObjectStateEntry - 维护实体状态的类
- ObjectStateManager - 实体状态管理器
示例
1、详解ObjectContext
ObjectContext.aspx
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
ObjectContext.aspx.cs
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2、事务和并发处理
ObjectContext2.aspx
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
ObjectContext2.aspx.cs
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
OK
[源码下载]