Refetch Issue

Posts   
 
    
Jeff M
User
Posts: 250
Joined: 04-Aug-2004
# Posted on: 17-Jan-2006 21:15:54   

Hello LLBLGen'ers.

Using the current release verion of GenPro, VS2005, remoting and adapter. I'm creating a new entity in the client code: new CategoryEntity(). Upon save, a trigger in the database creates a related record in CategoryDetail. The problem is, the refetch doesn't retrieve the related CategoryDetail record because, obviously, there was no Prefetch path. When I try to create a new CategoryEntity using:

        
public CatalogueCategoryEntity GetCatalogueCategory()
   {
       CategoryEntity ent = new CategoryEntity();
       IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.CategoryEntity);
       prefetchPath.Add(CategoryEntity.PrefetchPathCategoryDetail);
       DataAccessAdapter adapter = new DataAccessAdapter();
       adapter.FetchEntity(ent, prefetchPath);
       return ent;
   }

and then I try to save, I get a database generated error. It appears that no prefetch graph can be generated on a non-existant entity.

I would like to Refetch a new entity with related collections. Is this doable?

Thanks.

Jeff

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-Jan-2006 06:43:19   

The code you showed tries to Fetch an Entity with no Primary Key using FetchEntity !!!

and then I try to save

Do you use this before saving the entity in the first place? (not possible)

The possible scenario is: 1- Save the Entity to the database. 2- if the Entity has an Identity(database generated) PK, passing true to the refetchAfterSave parameter of the SaveEntity(), this will update the entity with it's PK 3- Either to Fetch the Entity using its PK along with its related Entities using PrefetchPath. 4- Or Just Fetch The related Entities into a collection using FetchEntityCollection using a FK (The main Entity PK) as a filter. or by using something like this: EntityCollection orders = customer.Orders; adapter.FetchEntityCollection(orders, customer.GetRelationInfoOrders()); Where customer is your newly saved and refetched main Entity.

Jeff M
User
Posts: 250
Joined: 04-Aug-2004
# Posted on: 19-Jan-2006 04:33:55   

Walaa wrote:

The possible scenario is: 1- Save the Entity to the database. 2- if the Entity has an Identity(database generated) PK, passing true to the refetchAfterSave parameter of the SaveEntity(), this will update the entity with it's PK 3- Either to Fetch the Entity using its PK along with its related Entities using PrefetchPath.

Yes - this is what I'm doing now, however it's a two-step process. (1) perform adapter.EntitySave(newEntity) followed by (2) a fetch.

I was wondering if it could be done in a single step - by using Refetch. I guess not.

Jeff

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 19-Jan-2006 06:57:45   

Can't be done in a single step.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39932
Joined: 17-Aug-2003
# Posted on: 20-Jan-2006 10:56:44   

Just a quicky:

Walaa wrote:

1- Save the Entity to the database. 2- if the Entity has an Identity(database generated) PK, passing true to the refetchAfterSave parameter of the SaveEntity(), this will update the entity with it's PK

The PK is always set after the save, no refetch is needed. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
swallace
User
Posts: 648
Joined: 18-Aug-2003
# Posted on: 20-Jan-2006 15:38:58   

LLBLGen'ers

I think I want a T-shirt that says I'm an LLBLGen'er. simple_smile

(Seriously, you should look at http://www.cafepress.com/cp/info/sell/ and offer something. We did it for my kids' schools and it's no cost to set up. You just submit the logo and they print on demand.)