INSERT statement executed but UPDATE expected

Posts   
 
    
KIT
User
Posts: 59
Joined: 04-Apr-2007
# Posted on: 30-Aug-2007 10:44:18   

Adapter / v.2.0

Hi,

I am currently facing a strange problem when trying to update an entity. The object model I have looks as follows:

  • Customer entity with "n" linked order entities

Now, I am reading a single customer entity and prefetch all the order entities. Then I wanna execute an operation on one of the prefetched order entities. The code looks like this:

order.Document = doc.Id;
bool test = order.IsNew; // result is FALSE, so the entity is not new
DataAdapter.SaveEntity(order, true); // --> Exception!

The exception occurs because a field is set to NULL but it can't be NULL in the db. So I started to investigate and found out that a INSERT instead of an UPDATE statement is executed! Why??? How is that possible?

I actually know a workaround (using UpdateEntitiesDirectly) but I was wondering how that can be possible!?!

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 30-Aug-2007 11:22:06   

Please post a complete code snippet, generated SQL Query, and LLBLGen Pro runtime library version. (ref: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7725)

KIT
User
Posts: 59
Joined: 04-Apr-2007
# Posted on: 31-Aug-2007 14:07:20   

Sorry, I found the problem. A silly bug in my code.. rage