Recursive fetch with Adapter

Posts   
 
    
pvilanova
User
Posts: 24
Joined: 01-Apr-2007
# Posted on: 24-Apr-2007 17:15:11   

There is any built-in feature to recursive fetch all dependent collections? I've try with this code, but isnt working:

private static void FetchDependentCollections(IEntity2 entity, DataAccessAdapter adapter) { List<IEntityCollection2> colls = entity.GetMemberEntityCollections(); foreach (IEntityCollection2 coll in colls) { adapter.FetchEntityCollection(coll, null); IEntity2 ent = adapter.FetchNewEntity(coll.EntityFactoryToUse, new RelationPredicateBucket()); FetchDependentCollections(ent, adapter); } }

Regards.

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 24-Apr-2007 17:18:47   

Hello,

you just have to defined the prefetchpaths and make only one fetchentity(or entitycollection) to have an entity/entitycolleciton and all the linked entities.

pvilanova
User
Posts: 24
Joined: 01-Apr-2007
# Posted on: 24-Apr-2007 17:26:10   

Do you hace a generic method already coded?

Can you post an example?

Regards.

pvilanova
User
Posts: 24
Joined: 01-Apr-2007
# Posted on: 24-Apr-2007 17:44:43   

I want a generic method. If i change the database, i can generate again and do not change the method.

Greets.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Apr-2007 10:05:56   

I want a generic method. If i change the database, i can generate again and do not change the method.

What do you mean by "If I change the database"?

pvilanova
User
Posts: 24
Joined: 01-Apr-2007
# Posted on: 25-Apr-2007 12:28:09   

Imagine i an entity A with a collection of B entities. Now i change the schema and A has 2 collections, B entities and C entities. If i have a generic recursive dependent collection fetch method, the code do not change.

Regards.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Apr-2007 16:47:01   

You should use the Designer to re-fresh the catalog and regenerate the code and re-build the solution. Otherwise how would a new property be created inside the main entity to map/reference the new related table/entity. Also which is more important you won't find the corresponding object/class created to map the new table.

In O/R mapper: schema change = re-generate code.

pvilanova
User
Posts: 24
Joined: 01-Apr-2007
# Posted on: 25-Apr-2007 21:43:31   

I know i must generate again, that's not the point.

What i need is a recursive fetch. If i have an entity of type A with a collection of entities of type B, i need to fetch entity A, and automatically fetch all entities of type B related with that particular entity of type A.

And i want a generic method, that works for any given type A.

Regards.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Apr-2007 10:51:55   

Using PrefetchPaths you can perform recursive fetches. Now if you want a generic method, the method should know at run time which type and entity to fetch and which related entities to fetch along. Since for any given entity type you may have more than one type of related entities.

So you can have a method which takes a prefetchPathElement as a paramter, along with the entity, or type to fetch.

pvilanova
User
Posts: 24
Joined: 01-Apr-2007
# Posted on: 26-Apr-2007 12:11:55   

Ok, thanks.

Can you post an example?

Regards.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Apr-2007 16:17:39   

Well the DataAccessAdapter FetchEntity() method can be that generic method, which is infact the main pupose of the DataAccessAdapter class and its methods, this function takes the following parameters (IEntity2 ..., IPrefetchPath2 ...).

if for some reason you can't use this function directly, specify that reason, and specify which information is available to you before making the fetch call.