views:

285

answers:

1

I am trying to perform a query on a query result, but I am getting an error: “The method or operation is not implemented”. Can I chain queries in this way? For example, I have a Northwind typed DataSet. I do:

  queryResult = From product In NorthWindDataSet.Products
                      Where (product.UnitsOnOrder > CInt(txtUnitsOnOrderFilter.Text))
                      Select product

Then I try to do

queryResult = From product In queryResult
                Where (product.CategoryID = cboCategoryFilter.SelectedValue)
                Select product

To finally use result of a query as a binding source: ProductsBindingSource.DataSource = queryResult.AsDataView()

How can I accomplish this?

A: 

LINQ to SQL is probably complaining about the CInt and SelectedValue calls in your queries. Try capturing those values outside your query instead:

Dim units = CInt(txtUnitsOnOrderFilter.Text)
Dim catId = cboCategoryFilter.SelectedValue

queryResult = From product In NorthWindDataSet.Products
              Where (product.UnitsOnOrder > units) AndAlso (product.CategoryID = catId)
              Select product
dahlbyk
I tried using literal values, as you suggested, for example Dim units = 2 and Dim catId = 3 but now I'm getting: "Can not create DataView after using projection" exception at System.Data.EnumerableRowCollection`1.GetLinqDataView(). It is important to me to be able to perform query on query result as I posted originally, since conditions are applied dynamically. This means that sometimes only units, sometimes only catId and sometimes both conditions are used.
Dan
Are you doing any sort of projection on queryResult after this filtering, maybe selecting out just Product.ID or something? That seems to what would cause that error. Also, have you tried just binding your data source to queryResult without calling AsDataView()?
dahlbyk