v3 - 1:n multiple inserts per one object

Posts   
 
    
miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 19-Jul-2010 16:07:48   

Hi.

we have a following Situation:

pseudo code:
class A
{
EntityCollection<B> BCollection{get;set;}
}

class B
{
A Parent {get; set;}
}

One of developers made a following assigment:

A a = new A();

B b = new B();

b.Parent = a;
a.BCollection.Add(b);

adapter.save(a);

The effect was one entity in A object and two entities of B object in the DB. We've fix this behaviour by removing extra assigment, but does a mentioned behavior is correct? I Know that we have a two references in the collection but they reference the same object.

Regards, MiloszeS

PS. Hope that I've clearly describe a problem.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 19-Jul-2010 16:27:10   

What's the value of a.BCollection.DoNotPerformAddIfPresent ?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 19-Jul-2010 17:36:33   

Also, the pk fields of the 'B' entities, are these identity?

It's a little odd, considering that the B entity is saved once (of course) and after that, it's no longer 'dirty' and therefore shouldn't result in a second insert statement.

You get the exact same insert statements?

Frans Bouma | Lead developer LLBLGen Pro
miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 20-Jul-2010 09:26:38   

Sorry for a confusion. I've find out that the reason why we had double inserts was our code + LLBLGen behavior. The scenario was:

  • serwer created a double links (assigment to the parent and assigment to the child)
  • refetch entity (not fetched again but simply refetch). so still we had two references in a child collection
  • transforms object to dto and send to client (because there were two references in a collection it created two objects)
  • client make some transformations and again send to serwer but now two objects, which were saved into the db.

I guess that I can switch that behaviour using the DoNotPerformAddIfPresent property on a collection. But the best option will be just not making a mentioned double assignments.