Windows Forms data binding and LINQ aren't fully compatible.
LINQ to Objects returns IEnumerable<T> collections - the simplest type of collection in .NET.
Windows Forms data binding is designed to work with BindingList<T> collections, which have more features.
So binding to a L2O query result in Windows Forms only works in the most simple scenarios.
Of course a read-only list is a simple scenario, and so what you are trying to do should generally work.
However, you might have better luck using the SortedBindingList and FilteredBindingList classes provided by CSLA .NET. These pre-date L2O and are designed primarily to support sorting and filtering in a way that works well with Windows Forms data binding.
Again, for your simpler scenario, L2O queries should work fine. Because this is LINQ to Objects, there is no database access - LINQ is just looping through the items in your collection and creating a new collection that only contains the items you specify based on your where clause.
Yes, the purpose of LinqBindingList is to provide better Windows
Forms support when doing a query over a BusinessListBase.
There’s no real tutorial because it is automatic. Any identity
projection query over a BusinessListBase will return a LinqBindingList – that just
happens with no effort. And LinqBindingList is a BindingList<T>, and is
also a view over the original list, so any insert/update/remove operations
affect the real list as well as the LBL view. Again, all automatic.
FilteredBindingList is also a view over the original list, and
so doesn’t talk to the database. In fact LinqBindingList is just a variation on
the pattern established by SortedBindingList and FilteredBindingList – all three
are just bindable views over the real collection.
To be clear, the LinqBindingList is only created for Editable Collections.
It is NOT created for Read Only Collections.
Also, there is a class called ObjectListView in CSLA Contrib which I used to use prior to LINQ. It has the advantage of being able to sort more than one field at a time which is a limitation of SortedBindingList.
Joe
I know this thread is a little bit old, but I'm just starting to play around with csla 3.8 (was using 3.0), and I'm still trying to wrap my head around a few concepts, and linqbindinglist is one of them.
The book mentions that sortedbindinglist and filteredbindinglist are still there just for backwards compatibility, and that linqbindinglist should replace them. However, by looking at Rocky's posts in this thread, it appears that they're still a valid option specially in windows applications. I have gotten it to work (to some extent) with linqbindinglist, but I have found some issues that make me wonder if sortedbindinglist would be a better option. But I don't want to start something new on classes that will be no longer supported.
So, what is the current status of sortedbindinglist? What is its future?
Copyright (c) Marimer LLC