title: DataTable's NewRow() method causes re-evaluation of LINQ expression after being used as a BindingSource with AsDataView()
body: <p>In the following code, I have a LINQ expression that produces an <code>EnumerableRowCollection(Of DataRow)</code> that is eventually used in a <code>BindingSource.</code></p>
  
  <p>The first time the code loops, it's fine.  However, once the <code>BindingSource</code> for the first <code>Control</code> has been set using <code>AsDataView()</code> on the <code>IEnumerable</code>, the next time the <code>NewRow()</code> method on the <code>DataTable</code> is called, it re-evaluates the LINQ expression.</p>
  
  <pre><code>Option Explicit On
  Option Infer Off
  Option Strict On
  
  Public Class Form1
      Dim ds As New DataSet()
  
      Private Sub Form1_Load( sender As Object,  e As EventArgs) Handles MyBase.Load
          ds.Tables.Add("Table1")
  
          Dim comparisonInteger As Integer = 12
          ds.Tables("Table1").Columns.Add("ID", GetType(Integer))
          ds.Tables("Table1").Columns.Add("IntegerValue", GetType(Integer))
          ds.Tables("Table1").Columns.Add("StringValue", GetType(String))
  
          ds.Tables("Table1").Rows.Add({1, 47, "row 1"})
          ds.Tables("Table1").Rows.Add({2, 2, "row 1"})
          ds.Tables("Table1").Rows.Add({3, 7, "row 1"})
          ds.Tables("Table1").Rows.Add({4, 6, "row 1"})
  
          For i As Integer = 0 To 2
              Dim iterator As Integer = i
              Dim tb As New TextBox()
  
              CreateNewRowIfMissing(comparisonInteger+i)
  
              Dim dataValue As EnumerableRowCollection(Of DataRow) =  ds.Tables("Table1").AsEnumerable() _
                                                                          .Where(Function(v) DirectCast(v("IntegerValue"), Integer) = comparisonInteger + iterator)
  
              Dim bs As New BindingSource(dataValue.AsDataView(), Nothing)
              Dim b As New Binding("Text", bs, "IntegerValue")
              b.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged
              tb.DataBindings.Add(b)
  
              tb.Location = New Point(10, 10 * Me.Controls.Count+1)
  
              Me.Controls.Add(tb)
          Next
      End Sub
  
      Private Sub CreateNewRowIfMissing(comparisonInteger As Integer)
  
          If  ds.Tables("Table1").AsEnumerable() _
                  .Where(Function(v) DirectCast(v("IntegerValue"), Integer) = comparisonInteger) _
                  .Count() = 0
  
              ds.Tables("Table1").Rows.Add(ds.Tables("Table1").NewRow()) 'Prompts the dataValue IEnumerable to begin evaluating again.
              ds.Tables("Table1").Rows(ds.Tables("Table1").Rows.Count-1)("ID") = ds.Tables("Table1").Rows.Count
              ds.Tables("Table1").Rows(ds.Tables("Table1").Rows.Count-1)("IntegerValue") = comparisonInteger
              ds.Tables("Table1").Rows(ds.Tables("Table1").Rows.Count-1)("StringValue") = "row" &amp; ds.Tables("Table1").Rows.Count.ToString()
          End If
      End Sub
  End Class
  </code></pre>
  
  <p>To clarify, I used to use a standard <code>DataView</code> with a <code>RowFilter</code> as the <code>BindingSource</code>, which worked:</p>
  
  <pre><code>Dim dv As New DataView(ds.Tables("Table1"))
  dv.RowFilter = "IntegerValue=" &amp; (comparisonInteger+iteratorValue)
  </code></pre>
  
  <p>However I felt it might be nicer to make use of LINQ instead.</p>
  
  <p>So, what's going on here?  Why is the LINQ expression the <code>DataView</code> was based on being re-evaluated on the call to the <code>DataTable</code>'s <code>NewRow()</code> method?  Is there any way I can prevent this?</p>
  
  <p>I had hoped that <code>AsDataView()</code> would have produced a <code>DataView</code> that would behave in the same way as the above two lines.</p>
  
  <p>As potential work-around, I've found that I can use this as the <code>BindingSource</code>'s <code>DataSource</code>:</p>
  
  <p><code>New DataView(dataValue.AsEnumerable().CopyToDataTable())</code></p>
  
  <p>However, I'm concerned about potential performance with such a line in the future, and that I might as well use the <code>DataView</code> with the <code>RowFilter</code> rather than the LINQ if it required the above line.</p>