tags:

views:

650

answers:

2

We develop Win32 application that access to SQL 2005 database through Linq to SQL. The issue is when 2 users access to same record (View and Edit)… User 1 update record (DataContext.SubmitChanges()), User 2 will continue to see old information until he restart application. So, we would like to update context of user 2… The solution that appears right now is to call DataContext.Refresh to sync object with SQL table… We wondering if other solution exist ?

Thank you

+2  A: 

I've noticed that Refresh can be really nasty depending on the data you've already grabbed from an entity, another solution is to reset the context you are using to a new instance.

context = new MyDataContext(ConnectionString);

This, at least in the scenarios where I am using it is less overhead and less DB calls.

Quintin Robinson
The issue with that is when we want to update entity that was attach to previous DataContext instance... A DataContext.SubmitChanges call update nothing because no change are detected... So, I think, I need to re-attach entity to new datacontext
Philippe sillon
Yes I admit I was frustrated by this as well, with pending changes on one context this becomes an issue. One of the LINQ quirks i'm beginning to live with.
Quintin Robinson
A: 

Have you looked at the ObjectTrackingEnabled property of the datacontext. Try setting it to false? Ref: http://www.rocksthoughts.com/blog/archive/2008/01/14/linq-to-sql-caching-gotcha.aspx