Hi, I'm feeling a little stupid right now, but was hoping for some more guidance on generics and the use of IEntityCollection2 and IEntity2. I'm using the self servicing option (is this my issue?) and want to do some pretty straight forward stuff with Generic Collections.
I don't think the scenario matters too much, but I'll use it for the sake of explanation. I want to build a TreeView (in Windows Forms) that takes a collection and then builds all the corresponding entities under that node.
For instance my class looks like this.
public class CollectionTreeNode : TreeNode
{
public CollectionTreeNode()
{
}
public TreeNode ConstructCollectionCollection()
{
TreeNode parentNode = new TreeNode(_collection.GetType().FullName);
if (this._collection == null)
throw new Exception("Collection must not be null");
else
{
foreach (IEntity2 entity in _collection)
{
parentNode.Nodes.Add(entity.Fields["Full Name"].CurrentValue.ToString());
}
}
return parentNode;
}
private IEntityCollection2 _collection;
public IEntityCollection2 Collection
{
get { return _collection; }
set { _collection = value; }
}
}
And from my code I create a collection of a known type, and fill that with data, create an instance of my CollectionTreeNode class and add the collection to it.
treeView2.BeginUpdate();
CollectionTreeNode ctn = new CollectionTreeNode();
CustomerCollection cc = new CustomerCollection();
cc.GetMulti(null);
ctn.Collection = (IEntityCollection2)cc;
treeView2.Nodes.Add(ctn.ConstructCollectionCollection());
treeView2.EndUpdate();
However, when I cast my collection in to IEntityCollection2 I get an error:
{"Unable to cast object of type 'DataAccessLayer.CollectionClasses.CustomerCollection' to type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollection2'."}
What am I missing here? I'm sure I've missed some of the theory about generics, but I'm having a hard time getting this going... Any help would be appreciated.
Cheers,
Stuart.