CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

Linq to SQL Implicit Entity Sharing across DataContexts

336 Views
Copy Code Show/Hide Line Numbers
 StockContext context = new StockContext();
 User user = context.Users.Where( uss => uss.Pk == 1).SingleOrDefault();
 Response.Write(user.FullName + "<br>"); 
 user.FullName = user.FullName + "!";
 
 
 StockContext context2 = new StockContext();
 User user2 = context.Users.Where(uss => uss.Pk == 1).SingleOrDefault();
 Response.Write(user2.FullName + "<br>");
 user2.FullName = user2.FullName + "!";
 
 
 context.SubmitChanges();
 context2.SubmitChanges();
 
  user2 = context.Users.Where(uss => uss.Pk == 1).SingleOrDefault();
  Response.Write(user2.FullName);
by Rick Strahl
  September 27, 2009 @ 2:34pm
Tags:
Description:
In this example user2 is the same instance as user so each save actually adds two !! to the name.

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate