Alternative to FilteredBindingList in Silverlight Suggestions

Alternative to FilteredBindingList in Silverlight Suggestions

Old forum URL: forums.lhotka.net/forums/t/7454.aspx


decius posted on Thursday, August 13, 2009

I just had a revalation today while I was porting some of my Csla 3.0.5.0 libraries up to Csla3.7 for Silverlight. There doesn't seem to be a Csla.FilteredBindingList in the CslaLight assembly :( Sorry if this is a RTFM question, but what should I use instead for filtered lists?

I appreciate the help. Thanks.

RockfordLhotka replied on Thursday, August 13, 2009

Generally you should use LINQ.

I view SBL and FBL as essentially obsolete, but of course I'll leave them in the framework while there's WinForms support, because WinForms likes them much better than it likes LINQ.

decius replied on Friday, August 14, 2009

Thanks, LINQ is something I'm dying to get more experience with anyway, but the dinosaurs in my office have been dragging their feet on adoption of it, so I rarely get to code for it. Looks like I now have even more an excuse to get them to get of their butts.

Just curious, I hadn't heard anything about WinForms disagreeing with LINQ. If you don't mind, do you care to elaborate on that?

Thanks a million Rocky.

BTW, just a suggestion: I would be all for marking the SLB & FLB classes and ctors with an Obsolete attribute, just without an exception thrown so not to break anything. Stuff like that would help slackers like me get aware sooner =P

RockfordLhotka replied on Friday, August 14, 2009

“Disagreeing” might be a strong word.

 

Windows Forms controls like to interact with collections that implement IBindingList. All the auto-sorting and so forth works through that interface, as does normal datagrid behaviors like rolling back when the user presses ESC or adding a new row when the user moves to the bottom of the datagrid.

 

None of those features exist on the results of a LINQ query, because LINQ returns an IEnumerable<T>, not an IBindingList.

 

CSLA .NET tries to mitigate this through the LinqBindingList, so if you do an identity projection query you’ll get back an LBL<T>, not an IEnumerable<T>.

 

// returns LBL

var data = from r in Customers where r.SalesTotal < 500000 select r;

 

But if you do a non-identity projection then you’ll get back a normal LINQ result: IEnumerable<T>.

 

// returns IEnumerable<T>

var data = from r in Customers where r.SalesTotal < 500000 select new { Id = r.Id, Name = r.Name, Sales = r.SalesTotal };

 

So while CSLA .NET tries to make LINQ work better for Windows Forms, the reality is that LINQ is part of the new wave of technologies, and Windows Forms is a legacy technology.

decius replied on Thursday, August 20, 2009

Funny you bring that up, because I was just battling the same thing recently, but for different reasons. 

On my last reply on this thread is a workaround for just that, allowing you to still use LINQ in WinForms, by exposing a factory method that performs the linq and then adding the IEnumerable to a newly constructed Csla List Object.

The only downside is that you have to encapsulate the LINQ in the factory method, but honestly I like this 100 X better than writing FLB/SLB anyway. (plus for my common tasks at work, encapsulation of the filter is usually preferred anyway).

Copyright (c) Marimer LLC