Casting LINQ resultset directly to a BusinessListBase object

Casting LINQ resultset directly to a BusinessListBase object

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


CrispinH posted on Friday, October 10, 2008

I've got a business collection object based on BusinessListBase which is bound to a couple of grids in different ways.  I'm trying to use LINQ to provide the two views that I need as well as the dynamic filterering of the common data.  This is in preference to the FilteredBindingList

A LINQ query on a produces a resultset of type IEnumerable(Of T) which therefore lacks the BusinessListBase properties that I'd like to pick up on (eg IsNew, IsDirty, etc) for the UI.

Of course I can create a new instance of my object and iterate through the LINQ resultset to populate it then bind that to the grids as appropriate. But what I'd really like to do is cast the LINQ resultset to directly my type that inherits from BusinessListBase (which a long way down the line implements IEnumerable).  I've worked out that DirectCast and CType don't work. So the question is: is it possible to return a strongly-typed (ie BusinessListBase) object from a LINQ query and if so how?

TIA

Crispin

JoeFallon1 replied on Friday, October 10, 2008

Yes it is possible.

You can thank Aaron Erickson of Magenic for this wonderful capability.

I am quite sure it is in the 3.6 code base. Not so sure about 3.5.

Joe

 

CrispinH replied on Friday, October 10, 2008

Joe

Thanks for the tip.  I'll take a look.  I'm on an earlier code base at the moment.

Crispin

JoeFallon1 replied on Friday, October 10, 2008

One of the really cool things about the returned result is that you can bind to it and change it and the *original* list stays up to date!

Joe

 

Copyright (c) Marimer LLC