Generic EntityCollection into an EntityCollection

Posts   
 
    
Bashar
User
Posts: 108
Joined: 11-Nov-2004
# Posted on: 25-Jan-2007 12:26:20   

How would you go about changing a generic EntityCollection into an EntityCollection?

The only 'workaround' I found was to iterate through the entities within the collection. Is there any easier, more elegant way.

Thanks!

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 25-Jan-2007 14:12:51   

Both the Generic and the nonGeneric forms implement the IEntityCollection(2) interface.

Casting to the interface should do the trick.

Bashar
User
Posts: 108
Joined: 11-Nov-2004
# Posted on: 27-Jan-2007 08:53:37   

When I do that, like so:

toReturn.NonGenericEntityCollection = DirectCast(GenericEntityCollection, IEntityCollection2)

I get: Option Strict On disallows implicit conversions from 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollection2' to 'ATC.ITAuto.DAL.HelperClasses.EntityCollection'.

What to do?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 27-Jan-2007 10:47:49   

Bashar wrote:

When I do that, like so:

toReturn.NonGenericEntityCollection = DirectCast(GenericEntityCollection, IEntityCollection2)

I get: Option Strict On disallows implicit conversions from 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollection2' to 'ATC.ITAuto.DAL.HelperClasses.EntityCollection'.

What to do?

To use a generic collection, you can cast it to an IEntityCollection2 type. I'm not sure what toReturn is here though and what NonGenericEntityCollection is.

Every entity collection, generic or non generic, implements IEntityCollection2. This means that you can use a variable of type IEntityCollection2 and set it to any generic/nongeneric collection you run into.

However, the nongeneric EntityCollection type in the helperclasses is really EntityCollection<EntityBase>, and it can't be cast from EntityCollection<SomeEntity>, as that would mean covariance which isn't supported by C# and VB.NET

Frans Bouma | Lead developer LLBLGen Pro