Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

How to: Retrieve Information As Read-Only (LINQ to SQL)

When you do not intend to change the data, you can increase the performance of queries by seeking read-only results.

You implement read-only processing by setting ObjectTrackingEnabled to false.


When ObjectTrackingEnabled is set to false, DeferredLoadingEnabled is implicitly set to false.

The following code retrieves a read-only collection of employee hire dates.

Dim db As New Northwnd("c:\northwnd.mdf")

db.ObjectTrackingEnabled = False 
Dim hireQuery = _
    From emp In db.Employees _
    Select emp _
    Order By emp.HireDate

For Each empObj As Employee In hireQuery
    Console.WriteLine("EmpID = {0}, Date Hired = {1}", _
            empObj.EmployeeID, empObj.HireDate)

Community Additions

© 2015 Microsoft