Duplicated Entities after upgrading to V2.0

Posts   
 
    
nunodg
User
Posts: 14
Joined: 14-Dec-2005
# Posted on: 10-Jul-2006 16:19:38   

After upgrading to V2.0 I get duplicated entities using this prefecth path:

Example Tables:

Master Table have 1 record Master Table MasterId 1

Detail Table have 2 records Detail Table DetailId MasterId 1 1 2 1

After executing this code,

IPrefetchPath2 path2 = new PrefetchPath2((int) EntityType.DetailEntity); path2.Add(DetailEntity.PrefetchPathMaster).SubPath. Add(MasterEntity.PrefetchPathDetail); DetailEntity entity = new DetailEntity(1); adapter.FetchEntity(entity, path2);

the collection entity.Master.Detail returns the following 3 records DetailId MasterId 1 1 1 1 2 1

It should return only 2 records.

If I edit the file MasterEntity.cs and add DoNotPerformAddIfPresent = true after creating the collection,


 public virtual EntityCollection<DetailEntity> Detail
 {
   ...
   _detail = new EntityCollection<DetailEntity>(new DetailEntityFactory());
   _detail.DoNotPerformAddIfPresent = true;
   ...
 }

the problem disappear, but I don't think this is a solution.

How can I fix this?

Thanks, Nuno

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39619
Joined: 17-Aug-2003
# Posted on: 10-Jul-2006 17:18:48   

DoNotPerformAddIfPresent is now set to false by default. This is a change documented in migrating your code.

However, duplicates shouldn't be fetched indeed. I'll look into it.

Frans Bouma | Lead developer LLBLGen Pro
nunodg
User
Posts: 14
Joined: 14-Dec-2005
# Posted on: 10-Jul-2006 17:30:03   

Thanks for your quick answer.

I Know that was a change but shouldn't the collection return only 2 records with DoNotPerformAddIfPresent set to true or false?

Thanks, Nuno

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39619
Joined: 17-Aug-2003
# Posted on: 10-Jul-2006 17:55:37   

Instead of:


 IPrefetchPath2 path2 = new PrefetchPath2((int) EntityType.DetailEntity);
path2.Add(DetailEntity.PrefetchPathMaster).SubPath.
Add(MasterEntity.PrefetchPathDetail);
DetailEntity entity = new DetailEntity(1);
adapter.FetchEntity(entity, path2);

do:


 IPrefetchPath2 path2 = new PrefetchPath2((int) EntityType.DetailEntity);
path2.Add(DetailEntity.PrefetchPathMaster);
DetailEntity entity = new DetailEntity(1);
adapter.FetchEntity(entity, path2);

as the relations already sync entities with eachother. you're fetching the detail data again, which is already there. As you didn't notice this before because the fetch wasn't resulting in a new entity, it is now.

If you want to fetch the master's details as well, you should simply start the path with the master, and then fetch the details as well (which you're doing as well) and find the detailentity with id 1 using FindMatches() on the master's Details collection.

Frans Bouma | Lead developer LLBLGen Pro
nunodg
User
Posts: 14
Joined: 14-Dec-2005
# Posted on: 12-Jul-2006 00:27:15   

Thanks for your answer.

Is this a solution or a workaround?

Nuno.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39619
Joined: 17-Aug-2003
# Posted on: 12-Jul-2006 09:18:10   

nunodg wrote:

Thanks for your answer.

Is this a solution or a workaround?

Nuno.

'it works', kind of solution. When I made the decision to switch off DoNotPerformAddIfPresent in prefetch paths (for performance reasons) it worked in all my testcases, however I now see that there's a situation which could cause problems. To avoid these problems, please fetch the entities differently, as I discussed.

Frans Bouma | Lead developer LLBLGen Pro
nunodg
User
Posts: 14
Joined: 14-Dec-2005
# Posted on: 12-Jul-2006 11:17:41   

Ok,

In what situations this problem occurs? Is only in this situation?

I need this info to check my code because I use a lot of Prefetch Paths.

Thanks,

Nuno

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39619
Joined: 17-Aug-2003
# Posted on: 12-Jul-2006 11:46:00   

You have this: Order m:1 Customer. You then first fetch Order A Then you fetch the Customer related to A and all its orders. This thus includes Order A AGAIN.

To overcome this, simply fetch Customer and its orders. It will include A.

Frans Bouma | Lead developer LLBLGen Pro