Passing EntityCollections<TEntity> as parameter

Posts   
 
    
Posts: 28
Joined: 27-Mar-2007
# Posted on: 17-Apr-2007 18:40:43   

Hi, I am trying to create a generic handler for collections that use the Sort and FindMatches methods. Currently I pass in the Filter, EntityCollection and FieldIndex. I'm having trouble passing the EntityCollection. The idea is to use user entered text to alter the page and select indexes of the datagrid, effectively jumping to a selected page where the text matches. Here is the code

       public static void performSearch( GridView theGridView, 
                                          DetailsView theDetailsView,
                                          PredicateExpression Filter,
                                          EntityCollection<> theEntityCollection, 
                                          int sortField )
        {
            theEntityCollection.Sort(sortField, System.ComponentModel.ListSortDirection.Ascending);
            List<int> matchingIndexes = theEntityCollection.FindMatches(Filter);

            if (matchingIndexes.Count > 0)
            {
                theGridView.PageIndex = (matchingIndexes[0] > 0) ? (matchingIndexes[0] / theGridView.PageSize) : 0;
                theGridView.SelectedIndex = matchingIndexes[0] % theGridView.PageSize;
            }
        }
jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 17-Apr-2007 19:19:04   

try passing either IEntityCollection (interface) or just EntityCollection. Not EntityCollection<>.

EntityCollection<> requires a type within the brackets. This casts it to a specific entity which may defeat the purpose of this general function.

i also don't believe System.ComponentModel.ListSortDirection.Ascending is the same as the llbl SortOperator enumerator. Use SortOperator.Assecending instead.

if I'm way off base, or this this doesn't solve the problem, post the exception and stack trace.

Posts: 28
Joined: 27-Mar-2007
# Posted on: 18-Apr-2007 10:17:48   

Jason, Thanks for the information. IEntityCollection worked ok. I was trying to pass a generic collection generically and had tried the type suggested by intellisence e.g. EntityCollection<TEntity> as well as EntityBase2 and IEntity2. I wondered if I could pass a type through the interface and instance the collection in the helper object.

I get a casting error when I use SortOperator.Assecending in the sort method.

Thanks again for your help.

Michael

Posts: 28
Joined: 27-Mar-2007
# Posted on: 18-Apr-2007 11:02:17   

Jason, The change from EntityCollection<TEntity> to EntityCollection and the use of IEntityCollection does indeed satisfy the compiler. The method call required a cast to IEntityCollection for the collection parameter. The resulting call causes a runtime error as follows

Unable to cast object of type 'CaptureV4.Data.HelperClasses.EntityCollection' to type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollection'.

I tried EntityCollection and this worked ok without the need to cast.

Michael