I am trying to bind results returned from queries with dynamic where clauses to a WPF DataGrid.
Using Database.SqlQuery there seems to be no Load() method and no Local() to return an ObservableCollection.
Thus I am using New ObservableCollection(Of Product)(q1).
Is this the recommended usage, or am I missing something?
Using DbSet.SqlQuery I found no way to get at the data at all.
How is this supposed to be used?
Dim _dbc As New AdventureWorksEntities
''Using DbSet
'Dim q = _dbc.Product
'q.Load()
'Dim r = q.Local
'grd.ItemsSource = r
Const sql = "select * from production.product WHERE name LIKE 'fla%' and ProductNumber LIKE '%0'"
'Using Database.SqlQuery
Dim q1 = _dbc.Database.SqlQuery(Of Product)(sql)
Dim r1 = New ObservableCollection(Of Product)(q1)
grd.ItemsSource = r1
''Using DbSet.SqlQuery
'Dim q2 = _dbc.Product.SqlQuery(sql)
''Dim r2 = ???
''grd.ItemsSource = r2
You should be able to achieve what you are looking for by doing the following.
Also note that the results of
Database.SqlQuery()are never tracked in the context so you will have to useDbSet.SqlQuery()if you want to bind to the results usingDbSet.Local.For more information on what
DbSet.Localactually contains, please refer to its documentation.