LINQ to CSLA (ver 3.8.4): having a little issue with a Indexable Nullable<Guid> property on a ReadOnlyListBase<,> collection when indexing, caused by null values

LINQ to CSLA (ver 3.8.4): having a little issue with a Indexable Nullable<Guid> property on a ReadOnlyListBase<,> collection when indexing, caused by null values

Old forum URL:

Troncho posted on Thursday, May 10, 2012

Hi everybody. I'm working on a tree structure that builds around an in memory ReadOnlyListBase, which contains information about basic tree structures.

I get the inicial collection info to build the final trees and put the data in this ReadOnlyListBase collection

public class TreeListBase<TList, TNode> : ReadOnlyListBase<TList, TNode>
	where TList : TreeListBase<TList, TNode>
	where TNode : TreeNodeInfoBase<TNode, Guidstring>

which contains items of TreeNodeInfoBase:

public class TreeNodeInfoBase<T, TId, TInfo> : ReadOnlyBase<T>, ITreeNode<TId, TInfo>
	where T : TreeNodeInfoBase<T, TId, TInfo>
	where TId : struct

TreeNodeInfoBase has these properties:

private static PropertyInfo<TId> IdProperty = RegisterProperty<TId>(c => c.Id);
public TId Id
	get { return GetProperty(IdProperty); }
	protected set { LoadProperty(IdProperty, value); }
private static PropertyInfo<TId?> ParentIdProperty = RegisterProperty<TId?>(c => c.ParentId);
public TId? ParentId
	get { return GetProperty(ParentIdProperty); }
	protected set { LoadProperty(ParentIdProperty, value); }

 as you can see, ParentId is nullable and marked as Indexable.

 Later, when I build actual trees from this base classes, I use something like this.

var children = from data in selectList
 where data.ParentId == parentId
 orderby data.Orden
 select data;

selectList is any constructed type derived from TreeListBase<>, so this query executes the special Where(..) extension CSLA has on ReadOnlyListBase collections.

The Where(..) builds the index corresponding to "ParentId", and in the process, it leaves out of the index all the "null" references of ParentId. I'm following the code on Csla.Linq.Index<T>.DoAdd(..)


   private void DoAdd(T item)
     if (_theProp != null)
       object value = _theProp.GetValue(item, null);
       if (value != null)
         int hashCode = value.GetHashCode();
         if (_index.ContainsKey(hashCode))
           List<T> newList = new List<T>(1);
           _index.Add(hashCode, newList);


It asks "if (value != null)". If it is, it adds the calculated hashcode to the index structure. If not, it does nothing.

The issue I'm having comes when I try to build the tree using an [Indexable] ParentId property. My first step is to get all the root nodes on my tree. All these root nodes are expilcitly identified by having a Nullable<Guid> ParentId == null.

So, if I leave the [Indexable] attribute on, the index doesn't find any hit and the tree building fails. If I get rid of the [Indexable] attribute, everything works fine.

Its wonderful to have the ability to index on Csla collections and to accelerate processes like tree building. I have a couple of large tree collections that need to be rebuild upon different filters once and again. This indexing capability is very useful here.

Should I use the indexing structure in any other way, so nulls are included on the index lists?

Is there any way I can get the framework to include nulls on Linq to Csla indexes?

As I'm writing, I'm thinking about using some dummy value for my null values when I construct the Csla collection. This should do the trick. I'm looking for a more elegant solution here Smile

Thanks in advance,




RockfordLhotka replied on Thursday, May 10, 2012

Fwiw, we completely dropped this indexing functionality in CSLA 4. It is more reliable to use external indexing libraries than to try and maintain the functionality directly inside CSLA.

I don't think we supported the concept of null values in an indexed property, no.

alex.enjoy replied on Friday, May 11, 2012

This sounds very interesting to me.
Can you provide more information about indexing libraries, maybe an working example together with CSLA ?

thanks, alex.

JonnyBee replied on Friday, May 11, 2012

Http:// and probably others a well.

Troncho replied on Friday, May 11, 2012

Jonny, once again, thanks a lot for your advice on every subject I present on this forum. I'll check the indexing library you are suggesting and come back with the results Big Smile

Troncho replied on Friday, May 11, 2012

Ok, thanks for your quick answer Rocky. I'm trying to advance as quickly as possible with my first solution around CSLA 3.8

I'm really looking forward to finish this first project developed on CSLA 3.8 / WinForms

Next one will be on CSLA 4 (I will have to learn all the new stuff you suggest) and MVC.

Copyright (c) Marimer LLC