Bug in LinqBindingList

Bug in LinqBindingList

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


Vinodonly posted on Wednesday, June 02, 2010

I changed the csla version to 3.8.3 with the hope this problem will be solved but it remains same.. I'm using VS 2010 Prof on Win 7 with csla 3.8.3 (Winforms)..

I'm using following line to get filtered list from my BO 

FilteredList =

 

 

from T in _TAList

 

 

where T.InfoType == InfoType

 

 

select T;

 

 Upto this point everything is ok, i'm getting filtered list..

Now i need to replace one column from this filtered list.. When i run the for each loop on this fitlered list (which is having 107 items), replacing code is not executed and straight away the code jumps to the next line after this..

Can somebody help me with this..

 

 

 

foreach (var item in

FilteredList)

RockfordLhotka replied on Wednesday, June 02, 2010

You can block CSLA from generating an LBL by adding .ToList() to your _TAlist:

from T in _TAlist.ToList() where ... select T;

That's probably your best bet, since it doesn't sound like you want or need an LBL anyway.

CSLA 4 gets rid of this automatic creation of an LBL - if you want one it is an explicit request you must make.

Vinodonly replied on Wednesday, June 02, 2010

Noted below point but if i do that then how i can replace cols in underlying filtered bo..

For this eg. i just showed one query but i'm doing filtering on other cols also and finally giving option to user for a quick replace within the filtered list.. Kindly advs..

RockfordLhotka replied on Wednesday, June 02, 2010

Maybe I don't understand what you are trying to do.

You are saying that you do the query, and the foreach does not traverse any items? So the result of the query is empty?

Vinodonly replied on Wednesday, June 02, 2010

Sorry i will explain in detail..

I'm giving option to user where he can do filtering on this list (For eg. items of a specific Infotype) and then he can do replacing on that filtered list..

For eg. out of 1000 items, he first filtered item with infotype = 1.. now he wants to replace this infotype to say 2..

With the for each loop i'm replacing single entry at a time..

 

foreach

 

 

 

(var item in

FilteredList)

ReplaceSingleEntry(item);

 

Kindly also note that FilteredList retrieved via linq query is also databinded to winforms (as user can see the recs which he has filtered)

_TACtrl.tAListBindingSource.DataSource = FilteredList;

Problem is that although the filteredlist in debugger is showing count as 107 and even i can see the filtered records on the screen but when the for each loop is executed, my method or replacing each item is never executed.. if i executed the same code without linq i.e. directly on bo then my foreach loop works perfectly but with linq it is not getting executed..

 

 

 

 

 

RockfordLhotka replied on Wednesday, June 02, 2010

I am unable to replicate your issue. This code works (simple console app referencing Csla.dll 3.8.3):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla;

namespace ConsoleApplication1
{
  class Program
  {
    static void Main(string[] args)
    {
      var root = DataPortal.Fetch<TestList>();
      var filtered = from r in root
                     where r.Id > 2
                     select r;
      foreach (var item in filtered)
        Console.WriteLine(item.Id);
      Console.ReadLine();
    }
  }

  [Serializable]
  public class TestList : BusinessListBase<TestList, TestItem>
  {
    protected void DataPortal_Fetch()
    {
      RaiseListChangedEvents = false;
      Add(DataPortal.FetchChild<TestItem>(1, "a"));
      Add(DataPortal.FetchChild<TestItem>(2, "w"));
      Add(DataPortal.FetchChild<TestItem>(3, "b"));
      Add(DataPortal.FetchChild<TestItem>(4, "z"));
      RaiseListChangedEvents = true;
    }
  }

  [Serializable]
  public class TestItem : BusinessBase<TestItem>
  {
    private static PropertyInfo<int> IdProperty = RegisterProperty<int>(c => c.Id);
    public int Id
    {
      get { return GetProperty(IdProperty); }
      set { SetProperty(IdProperty, value); }
    }

    private static PropertyInfo<string> NameProperty = RegisterProperty<string>(c => c.Name);
    public string Name
    {
      get { return GetProperty(NameProperty); }
      set { SetProperty(NameProperty, value); }
    }

    private void Child_Fetch(int id, string name)
    {
      using (BypassPropertyChecks)
      {
        Id = id;
        Name = name;
      }
    }
  }
}

Vinodonly replied on Monday, June 07, 2010

I checked this issue in detail and below are the details for the same..

In LinqBinding List Line 874

 

var subset = (_list as Linq.IIndexSearchable<T>).SearchByBLOCKED EXPRESSION.GenericParameterPosition' threw an exception of type 'System.InvalidOperationException'

    GUID: {79a71847-1936-3eef-aef0-5baf854a6b51}

    HasElementType: false

    IsAbstract: false

    IsAnsiClass: true

    IsArray: false

    IsAutoClass: false

    IsAutoLayout: true

    IsByRef: false

    IsClass: true

    IsCOMObject: false

    IsContextful: false

    IsEnum: false

    IsExplicitLayout: false

    IsGenericParameter: false

    IsGenericType: false

    IsGenericTypeDefinition: false

    IsImport: false

    IsInterface: false

    IsLayoutSequential: false

    IsMarshalByRef: false

    IsNested: false

    IsNestedAssembly: false

    IsNestedFamANDAssem: false

    IsNestedFamily: false

    IsNestedFamORAssem: false

    IsNestedPrivate: false

    IsNestedPublic: false

    IsNotPublic: false

    IsPointer: false

    IsPrimitive: false

    IsPublic: true

    IsSealed: false

    IsSecurityCritical: true

    IsSecuritySafeCritical: false

    IsSecurityTransparent: false

    IsSerializable: true

    IsSpecialName: false

    IsUnicodeClass: false

    IsValueType: false

    IsVisible: true

    MemberType: TypeInfo

    Module: {Order.dll}

    Namespace: "OM.BO.OrderNs.HRNs.TA"

    ReflectedType: null

    StructLayoutAttribute: {System.Runtime.InteropServices.StructLayoutAttribute}

    TypeHandle: {System.RuntimeTypeHandle}

    TypeInitializer: null

    UnderlyingSystemType: {Name = "TAList" FullName = "OM.BO.OrderNs.HRNs.TA.TAList"}

 

Vinodonly replied on Monday, June 07, 2010

my msg didn't come properly in previous msg.. i'm attaching a text file with all details

RockfordLhotka replied on Monday, June 07, 2010

Can you take my simple example (previous post) and use it to replicate your problem? I need a simple repro of the issue to troubleshoot.

Copyright (c) Marimer LLC