Is the LINQ extension methods like where(Type, Int32, boolean) supported by the BusinessListBase?

Is the LINQ extension methods like where(Type, Int32, boolean) supported by the BusinessListBase?

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


Killian35 posted on Thursday, March 12, 2009

I was trying to apply the Where extension method to a BusinessListBase object using the index overloaded version, but the attempt didn't work. It came back with an exception about trying to convert the lambda(Type, Int32, bool) to lambda(Type, bool). I then just did a ToList on the BusinessListBase object then applied the Where extension with no problem. Is that overloaded method just not supported directly by the BusinessListBase?

Thank you,
Kelly

DivisibleByZero replied on Thursday, March 12, 2009

If BusinessListBase implements IEnumerable<T> then it would work. Maybe you had your lambda wrong?

class ChildList : BusinessListBase<ChildList, Child>
{
   public IEnumerable<Child> Select(string foo)
   {
         return this.Where( c => c.Foo == foo );
   }
}
class Child : BusinessBase<Child>
{
    public string Foo { get; set }
}




Killian35 replied on Thursday, March 12, 2009

Thank you for your reply! However, I've failed to explain my problem correctly. I'm using the Where overload that accepts an index variable, like so:

var list = MyList.GetList();
var filtered = list.Where((emp, index) => index > 50); // does not work

This will use the current item's index within the list for the 'index' value. However, this does not work on a BusinessListBase class. This causes an Exception. Somewhere down in the code there is an attempt to cast the lambda(Type, Int32, bool) to lambda(Type, bool). It does work on a regular List<>, so the following works correctly:

var filtered = list.ToList().Where((emp, index) => index > 50); // works

So if I push the business list to a generic list, the Where LINQ works as expected, giving me access to the current item's index.

Thanks,
Kelly

RockfordLhotka replied on Friday, March 13, 2009

It is possible this is caused by LINQ to CSLA. Or by Collection<T> or BindingList<T>.

I'll add an item to the bug tracker so this gets looked at in more depth when Aaron has time.

JoeFallon1 replied on Friday, March 13, 2009

Cna you try 2 alternatives on your BLB class?

1. For MS Dynamic query extensions use a string for filtering:
var filtered = list.Where("index > 50");

2.Also use std LINQ syntax:

From x in list Where x.Index > 50

Do either (or both) of these work? They probably should.

Joe


 

Copyright (c) Marimer LLC