Refresh DataContext in LINQPad
.net, c#, datacontext, linq-to-sql, linqpad
Solution
This looks like a bug in LINQ-to-SQL.
You can re-initialize the LINQPad DataContext by instantiating it explicitly:
while(1 = 1)
{
var freshDC = new TypedDataContext();
var me = freshDC.MyEntities.FirstOrDefault();
...
}
Problem
Hi there I am struggling to deal with the following situation using LINQPad ``` While(1 = 1) { MyEntity _me = MyEntities.FirstOrDefault(); foreach(ChildEntity ce in MyEntity.ChildEntities) { Console.WriteLine(ce.Value); } System.Threading.Thread.Sleep(100000); } ``` Where MyEntity (and the ChildEntities collection) is an automatically created LINQ to SQL class. The rows in the underlying database may change independently of this script and I would like the ChildEntities collection to refresh from the database on each iteration of the While Loop. It currently does not. This does not work ``` this.Refresh(RefreshMode.OverwriteCurrentValues, _me); ``` nor does ``` this.Refresh(RefreshMode.OverwriteCurrentValues, _me.ChildEntities); ``` is there anyway that I can close and re-open the LINQPad DataContext (I am a premium subscriber)