易截截图软件、单文件、免安装、纯绿色、仅160KB

Linq to SQL DataContext Lifetime Management


Linq to SQL uses a DataContext to manage it's access to the database as well as tracking changes made to entities retrieved from the database. Linq to SQL has a persistent approach to managing its 'connection' to the database via this data context and it basically assumes that you use a single DataContext to make all of your data related access. This doesn't mean that it makes persistent connections to the database, but means that the DataContext instance maintains state about active result sets, which is especially important if change tracking is on which is the default.
This is somewhat contrary to other ORM tools which tend to have a static manager to which you pass entities or queries that are then returned. In that respect most other ORMs are stateless in their data connectivity and management object where LINQ to SQL clearly takes a connected approach where everything revolves around this single DataContext instance.  DataContext holds all the change management information and it makes it very difficult to transfer that context information to another DataContext. In short it's a very different approach and requires some thinking about how you create and manage the DataContext object.
BTW, the ADO.NET Entity framework too uses a similar connected approach with its ObjectContext object which also manages state persistently and requires that you keep the object around if you want to do things like track changes.
This raises some interesting questions on how to manage the lifetime of the DataContext object. There are a lot of options of how you can deal hanging on (or not) to the DataContext. Here are a few different approaches:
Create a new Context for each atomic operation (Application level management)
Create a global DataContext and handle all operations against this single DataContext object
Create a thread specific DataContext
Create a per business object DataContext
What doesn't work
The first thing to understand is if you are coming from an


相关文档:

sql 2005 存储过程分页 java 代码

 create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',         
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列 ......

【摘】存储过程比较动态SQL的优点在哪里

存储过程跟动态sql相比有如下优点:
1、 存储过程允许标准组件式编程
存储过程在被创建以后可以在程序中被多次调用而不必重新编写该存储过程的SQL
语句而且数据库专业人员可随时对存储过程进行修改但对应用程序源代码毫无影响因
为应用程序源代码只包含存储过程的调用语句从而极大地提高了程序的可移植性
2 、存储过程 ......

SQL SERVER 存储过程简单案例

一、简单实例
1.首先来一个最简单的存储过程吧
CREATE PROCEDURE dbo.testProcedure_AX
AS
select userID from USERS order by userid desc
注:dbo.testProcedure_AX是你创建的存储过程名,可以改为:AXzhz等,别跟关键字冲突就行了,AS下面就是一条SQL语句.
2.如何在ASP.NET中调用这个存储过程?
     &n ......

sql—datediff 函数


 
DATEDIFF
   返回跨两个指定日期的日期和时间边界数。
   
   一、 语法 
   DATEDIFF ( datepart , startdate , enddate ) 
    
   二、参数
   datepar ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号