Generic Extension to convert IEntityCollection2 into Generic List

Posts   
 
    
redsquare
User
Posts: 3
Joined: 16-Apr-2009
# Posted on: 23-Apr-2009 21:36:11   

Hi,

Hi just started using the tool and it looks great.

I have the following wcf method which will fetch me any list. Obviosuly i need to transport it as IEntityCollection2. On the client end I would like to convert this into its generic list type. I can only do this if I create it in the service as a generic list which I cant do or have not worked out how to do.

Is there a clean way I can do this?

Thanks in advance.


public IEntityCollection2 GetList(EntityType entityType) {

            var col = new EntityCollection(EntityFactoryFactory.GetFactory(entityType));

            using (DataAccessAdapter adapter = new DataAccessAdapter()) {

                adapter.FetchEntityCollection(col, null);
            
                return col;
            }
}

rdhatch
User
Posts: 198
Joined: 03-Nov-2007
# Posted on: 24-Apr-2009 14:47:51   

Hi Red,

One way to do this would be to pass an actual entity instance instead of the type. This example will use Self-Servicing classes, because I'm more familiar with them than Adapter. For example:

Function GetList(Of TEntity as EntityBase)(ByVal Entity as TEntity) as EntityCollectionBase(Of TEntity)
GetList(New CustomerEntity)

Hope this helps!

Ryan

redsquare
User
Posts: 3
Joined: 16-Apr-2009
# Posted on: 24-Apr-2009 16:45:30   

Hi Ryan,

Thanks for that. Dont think I can do that as I am going over wcf. Will give it a try however.

Cheers Steve

rdhatch
User
Posts: 198
Joined: 03-Nov-2007
# Posted on: 24-Apr-2009 18:46:51   

Better yet, instead of passing the instance, could you not just pass the Generic type? Then there is no need to pass any arguments to your function.

Function GetList(Of TEntity as EntityBase) as EntityCollectionBase(Of TEntity)
GetList(Of CustomerEntity)

Ryan