Using DataContext to Track Changes and Cache Objects
2012-05-07 11:15
435 查看
The DataContext object manages object identity for you so that rows retrieved from the
database table are automatically logged in the DataContext object’s internal identity table
by the row’s primary key when the object is created. If the same row is retrieved again by this
DataContext object, the original instance is handed back to you. Your application sees only
the state of the row that was first retrieved. If, for example, you retrieve a row in your applica-
tion and the row is modified in the database table by a different application, you won’t get
the updated data if you query for this row again because the row is delivered to you from the
DataContext object’s cache.
It might seem rather weird that querying for the same row returned the original state of
the row, even though the row had been changed by another application. In essence, the new
data was thrown away. The reason for this behavior is that LINQ to SQL needs this behavior to
support optimistic concurrency. DataContext contains a method called SubmitChanges, which
sends all your changes back to the database table. This is explained in more detail later in this
lesson.
database table are automatically logged in the DataContext object’s internal identity table
by the row’s primary key when the object is created. If the same row is retrieved again by this
DataContext object, the original instance is handed back to you. Your application sees only
the state of the row that was first retrieved. If, for example, you retrieve a row in your applica-
tion and the row is modified in the database table by a different application, you won’t get
the updated data if you query for this row again because the row is delivered to you from the
DataContext object’s cache.
It might seem rather weird that querying for the same row returned the original state of
the row, even though the row had been changed by another application. In essence, the new
data was thrown away. The reason for this behavior is that LINQ to SQL needs this behavior to
support optimistic concurrency. DataContext contains a method called SubmitChanges, which
sends all your changes back to the database table. This is explained in more detail later in this
lesson.
相关文章推荐
- A Data Access Layer to persist business objects using attributes and reflection - Part III [无常译]
- A Data Access Layer to persist business objects using attributes and reflection - Part I
- A Data Access Layer to persist business objects using attributes and reflection - Part III
- A Data Access Layer to persist business objects using attributes and reflection - Part I [无常译]
- A Data Access Layer to persist business objects using attributes and reflection - Part II [无常译]
- Data Structures and Other Objects Using C++ (Chapter 1) 学习笔记二
- Using R to read and plot the csv data
- How To Read and Write BLOB Data by Using ADO.NET with Visual C# .NET
- How To Perform a Full Export And Exclude Certain Schemas Using The Data Pump API? [ID 1340781.1]
- Collecting performance counters and using SQL Server to analyze the data
- 102.You want to import schema objects of the HR user using Oracle Data Pump from the development dat
- A Novel Approach to Data Retrieval and Instrumentation Control at Remote Field Sites using Python and Network News
- Big Data Counting: How To Count A Billion Distinct Objects Using Only 1.5KB Of Memory
- Data Structures and Other Objects Using C++ (Chapter 2) 学习笔记四
- Convert XML data to object and back using serialization
- how to select data in multiple datatables after using join,group by and order by in Linq
- 15 Step To Hacking Windows Using Social Engineering Toolkit And Backtrack 5
- Using Imagecache and CCK Imagefield to Add an Image in Drupal
- Using Record Objects to perform inserts and updates