Help with a custom code inspection

Hi all:

We found a bug in LINQ to SQL that can lead to connection leakage.  It's a pretty simple pattern:

var aQuery = theContext.AnyIQueryableExpressionThatDoesNotForceAnExecution();
foreach(var item in aQuery)
{
  theContext.SubmitChanges()
}

The fix is simple:
var aQuery = theContext.AnyIQueryableExpressionThatDoesNotForceAnExecution();
var theResults = aQuery.ToList();
foreach(var item in theResults)
{
  // do stuff
  theContext.SubmitChanges()
}


So, the search pattern below will find my simple example above, but if there is one line of code between the opening brace in the foreach and the call to SubmitChanges, it doesn't find it.
It's as though it's ignoring the $statements$ placeholder

foreach ($itemType$ $item$ in $query$)
{
     $statements$
    $ctx$.SubmitChanges();
}


$item$ : identifier
$statements$: any number of statements
$itemType$ : typePlaceholder (any)
$query$: expression of type IQueryable
$ctx$: expression of type DataContext

This is my first code inspection -- can anyone see what I'm doing wrong?

2 comments
Comment actions Permalink

What version of ReSharper are you using? I've just tried this on 9.2 EAP3, and it works as expected - the foreach statement is highlighted if there's a line before the SubmitChanges or not.

0
Comment actions Permalink

I didn't realize that I didn't have the latest -- I was on 9.0.0 Update 1.  After I pulled the latest release, it started working.  
Thanks

0

Please sign in to leave a comment.