How to get the type

Posts   
 
    
kem
User
Posts: 13
Joined: 13-Oct-2009
# Posted on: 13-Oct-2009 10:17:48   

I just need to create a variable that is reated from a EntytyCollection's entity's such as:

EntityCollection<TEntity> mCol is my entytycollection. TEntity is the type of element of my entytycollection. It is actually type of TEntity : SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2, SD.LLBLGen.Pro.ORMSupportClasses.IEntity2 And finally TEntity entity = ((TEntity)t); here _ t_ should be a variable that is created from entitycollection's entity.

I can do it in foreach clause such as:

foreach (TEntity t in MyEntytyCollection) { TEntity entity = ((TEntity)t); } How can i do that without a foreach?

Thanks...

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 13-Oct-2009 11:01:31   

Why don't you use: foreach (entity in mCol) { entity... }

kem
User
Posts: 13
Joined: 13-Oct-2009
# Posted on: 13-Oct-2009 11:05:44   

Walaa wrote:

Why don't you use: foreach (entity in mCol) { entity... }

I just don't need it, because i don't need to goto each entity in collection. Need just one created from entity in collection.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 13-Oct-2009 21:38:54   

would


TEntity entity = (MyEntiityCollection[0] as TEntity);

do the trick...?

It does assume that you have at least one entity in your collection. Alternativly you could look at using reflection to dynamically instantiate an entity from a given type...

Matt

kem
User
Posts: 13
Joined: 13-Oct-2009
# Posted on: 14-Oct-2009 10:58:08   

Thanks, i will try this.

MTrinder wrote:

would


TEntity entity = (MyEntiityCollection[0] as TEntity);

do the trick...?

It does assume that you have at least one entity in your collection. Alternativly you could look at using reflection to dynamically instantiate an entity from a given type...

Matt