C#学习经典方法之(五)--LINQ中的DataContext类
2016-11-29 22:24
441 查看
Represents the main entry point for the LINQ to SQL framework.
命名空间:
System.Data.Linq
程序集: System.Data.Linq(位于 System.Data.Linq.dll)
继承层次结构
System.Object
System.Data.Linq.DataContext
语法:
属性:
方法:
备注
The DataContext is the source of all entities mapped over a database connection.
It tracks changes that you made to all retrieved entities and maintains
an "identity cache" that guarantees that entities retrieved more than
one time are represented by using the same object instance.
In general, a DataContext instance is designed to last for one "unit of work" however your application defines that term. A DataContext is lightweight and is not expensive to create. A typical LINQ to SQL application creates DataContext instances at method scope or as a member of short-lived classes that represent a logical set of related database operations.
版本信息
.NET Framework
自 3.5 起可用
Windows Phone Silverlight
自 7.1 起可用
线程安全
此类型的所有公共静态(Visual Basic 中的
已共享
在 Visual Basic 中)成员都是线程安全的。不保证所有实例成员都是线程安全的。
备注:转自https://msdn.microsoft.com/zh-cn/library/system.data.linq.datacontext.aspx
命名空间:
System.Data.Linq
程序集: System.Data.Linq(位于 System.Data.Linq.dll)
继承层次结构
System.Object
System.Data.Linq.DataContext
语法:
public class DataContext : IDisposable构造函数:
名称 | 说明 | |
---|---|---|
DataContext(IDbConnection) | Initializes a new instance of the DataContext class by referencing the connection used by the .NET Framework. | |
DataContext(IDbConnection,MappingSource) | Initializes a new instance of the DataContext class by referencing a connection and a mapping source. | |
DataContext(String) | Initializes a new instance of the DataContext class by referencing a file source. | |
DataContext(String,MappingSource) | Initializes a new instance of the DataContext class by referencing a file source and a mapping source. |
名称 | 说明 | |
---|---|---|
ChangeConflicts | Gets a collection of objects that caused concurrency conflicts when SubmitChanges was called. | |
CommandTimeout | Gets or sets a value that increases the time-out period for queries that would otherwise time out during the default time-out period. | |
Connection | Gets the connection used by the framework. | |
DeferredLoadingEnabled | Gets or sets a value that indicates whether to delay-load one-to-many or one-to-one relationships. | |
LoadOptions | Gets or sets the DataLoadOptions associated with this DataContext. | |
Log | Gets or sets the destination to write the SQL query or command. | |
Mapping | Gets the MetaModel on which the mapping is based. | |
ObjectTrackingEnabled | Gets or sets a value that indicates whether object tracking is enabled. | |
Transaction | Gets or sets a local transaction for the .NET Framework to use to access the database. |
名称 | 说明 | |
---|---|---|
CreateDatabase() | Creates a database on the server. | |
CreateMethodCallQuery<TResult>(Object,MethodInfo,Object[]) | 此 API 支持 产品 基础结构,不应从代码直接使用。 Executes the table-valued database function associated with the specified CLR method. | |
DatabaseExists() | Determines whether the associated database can be opened. | |
DeleteDatabase() | Deletes the associated database. | |
Dispose() | Releases all resources used by the current instance of the DataContext class. | |
Dispose(Boolean) | Releases the unmanaged resources used by the DataContext class and optionally releases the managed resource. | |
Equals(Object) | Determines whether the specified object is equal to the current object.(继承自 Object。) | |
ExecuteCommand(String,Object[]) | Executes SQL commands directly on the database. | |
ExecuteDynamicDelete(Object) | Executes, inside delete override methods, to redelegate to LINQ to SQL the task of generating and executing dynamic SQL for delete operations. | |
ExecuteDynamicInsert(Object) | Executes, inside insert override methods, to redelegate to LINQ to SQL the task of generating and executing dynamic SQL for insert operations. | |
ExecuteDynamicUpdate(Object) | Executes, inside update override methods, to redelegate to LINQ to SQL the task of generating and executing dynamic SQL for update operations. | |
ExecuteMethodCall(Object,MethodInfo,Object[]) | 此 API 支持 产品 基础结构,不应从代码直接使用。 Executes the stored database procedure or scalar function associated with the specified CLR method. | |
ExecuteQuery(Type,String,Object[]) | Executes SQL queries directly on the database. | |
ExecuteQuery<TResult>(String,Object[]) | Executes SQL queries directly on the database and returns objects. | |
Finalize() | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(继承自 Object。) | |
GetChangeSet() | Gets the modified objects tracked by DataContext. | |
GetCommand(IQueryable) | Gets the information about SQL commands generated by LINQ to SQL. | |
GetHashCode() | Serves as the default hash function.(继承自 Object。) | |
GetTable(Type) | Returns a collection of objects of a particular type, where the type is defined by the type parameter. | |
GetTable<TEntity>() | Returns a collection of objects of a particular type, where the type is defined by the TEntity parameter. | |
GetType() | Gets the Type of the current instance.(继承自 Object。) | |
MemberwiseClone() | Creates a shallow copy of the current Object.(继承自 Object。) | |
Refresh(RefreshMode,IEnumerable) | Refreshes a collection of entity objects according to the specified mode. | |
Refresh(RefreshMode,Object) | Refreshes an entity object according to the specified mode. | |
Refresh(RefreshMode,Object[]) | Refreshes an array of entity objects according to the specified mode. | |
SubmitChanges() | Computes the set of modified objects to be inserted, updated, or deleted, and executes the appropriate commands to implement the changes to the database. | |
SubmitChanges(ConflictMode) | Sends changes that were made to retrieved objects to the underlying database, and specifies the action to be taken if the submission fails. | |
ToString() | Returns a string that represents the current object.(继承自 Object。) | |
Translate(DbDataReader) | Converts an existing DbDataReader to objects. | |
Translate(Type,DbDataReader) | Converts an existing DbDataReader to objects. | |
Translate<TResult>(DbDataReader) | Converts an existing DbDataReader to objects. |
The DataContext is the source of all entities mapped over a database connection.
It tracks changes that you made to all retrieved entities and maintains
an "identity cache" that guarantees that entities retrieved more than
one time are represented by using the same object instance.
In general, a DataContext instance is designed to last for one "unit of work" however your application defines that term. A DataContext is lightweight and is not expensive to create. A typical LINQ to SQL application creates DataContext instances at method scope or as a member of short-lived classes that represent a logical set of related database operations.
版本信息
.NET Framework
自 3.5 起可用
Windows Phone Silverlight
自 7.1 起可用
线程安全
此类型的所有公共静态(Visual Basic 中的
已共享
在 Visual Basic 中)成员都是线程安全的。不保证所有实例成员都是线程安全的。
备注:转自https://msdn.microsoft.com/zh-cn/library/system.data.linq.datacontext.aspx
相关文章推荐
- C#学习经典方法之(五)--LINQ to SQL
- C#学习经典方法之(一)--装箱和取消装箱
- C#学习经典方法之(七)---List的FirstOrDefault
- [深入学习C#]LINQ查询表达式详解(1)——基本语法、使用扩展方法和Lambda表达式简化LINQ查询
- C#学习经典方法之(八)---XmlNode.OuterXml属性
- C#学习经典方法之(三)---String.Join方法
- c#经典入门学习笔记-封箱和拆箱
- C# 函数方法大全+学习笔记
- C#中常用的经典文件操作方法
- Asp.Net--DropDownList与DataTable数据绑定的方法(C#)[学习笔记]
- c#经典入门学习笔记-定义集合
- C#2005 .NET3.0高级编程学习笔记————类和结构,类的数据成员,类的函数成员(方法、属性)
- vs.net快速开发windows服务(c#)方法学习
- [Source Code]学习了一种比较经典的遍历XML文件的方法
- c#经典入门--学习笔记
- c#经典入门学习笔记-结构类型与对象的比较
- C# 静态成员和方法的学习小结
- C#学习之静态成员和非静态成员,构造函数,方法,方法参数,操作符重载,事件
- 学习手记,网文摘录--C#验证输入的是否数字的方法
- C# 静态成员和方法的学习小结