您的位置:首页 > 移动开发 > Objective-C

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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐