JohnnyBizzle
JohnnyBizzle

Reputation: 979

Stop LINQ to SQL caching

The database query run on SQL server (and the actual linq query using SQL Debugger http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx) show correct data. The object returned shows old data. How do I clear it? Both are doing a select

        Dim s As New StaffRecord
        Dim q = From staff As StaffRecord In db.StaffRecords _
                Where staff.Employee_Number = u.AssignmentNo _
                Select staff
        s = q.First

There is a possibility of 2 staff records with the same employee number, hence using .First instead of .Single

Upvotes: 2

Views: 844

Answers (1)

DamienG
DamienG

Reputation: 6665

You should create and destroy the datacontext per request. It is designed for that pattern and creates quickly and will prevent stale data.

Upvotes: 1

Related Questions