Error when saving collection async (Cache)

Posts   
 
    
Vestas
User
Posts: 6
Joined: 27-Jun-2008
# Posted on: 11-Mar-2010 11:06:21   

We have a problem when trying to save a EntityCollection to the DB. Our page use a async button to update a collection of 'order line' entities with serial numbers. Theis sn are in another table in the db and binded to the OrderLine as a relation. In our test we have three orderlines, we fill the serialno for all three, the one with a sn we know exist in the db. We now get an exception and this is fine. We now change sn to one we know do not exist in the db. Here our problem starts. We get this exception:

An exception was caught during the execution of an action query: Violation of UNIQUE KEY constraint 'UN_Serial_Number'. Cannot insert duplicate key in object 'dbo.Serial'. The statement has been terminated.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.

When we debug the collection right before the save method "DataAccessAdapter.SaveEntityCollection(collection, False, recurse)", we get the collection to contain the right three entities with the right three SN. But in the output window in VS2008 we get the LLBL generated SQL to try to insert the collections bindings more then one time:

Method Exit: CreateSelectDQ Method Exit: CreatePagingSelectDQ: no paging. Method Enter: CreateInsertDQ Method Enter: CreateSingleTargetInsertDQ Generated Sql query: Query: INSERT INTO [ComponentDoc].[dbo].[Serial] ([Number], [CreatedById], [ChangedById]) VALUES (@Number, @CreatedById, @ChangedById);SELECT @Id=SCOPE_IDENTITY() Parameter: @Id : Int64. Length: 0. Precision: 19. Scale: 0. Direction: Output. Value: <undefined value>. Parameter: @Number : String. Length: 50. Precision: 0. Scale: 0. Direction: Input. Value: "jewes10". Parameter: @CreatedById : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 34888. Parameter: @ChangedById : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 34888.

Method Exit: CreateSingleTargetInsertDQ Method Exit: CreateInsertDQ Method Enter: CreateInsertDQ Method Enter: CreateSingleTargetInsertDQ Generated Sql query: Query: INSERT INTO [ComponentDoc].[dbo].[Serial] ([Number], [CreatedById], [ChangedById]) VALUES (@Number, @CreatedById, @ChangedById);SELECT @Id=SCOPE_IDENTITY() Parameter: @Id : Int64. Length: 0. Precision: 19. Scale: 0. Direction: Output. Value: <undefined value>. Parameter: @Number : String. Length: 50. Precision: 0. Scale: 0. Direction: Input. Value: "jewes08". Parameter: @CreatedById : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 34888. Parameter: @ChangedById : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 34888.

Method Exit: CreateSingleTargetInsertDQ Method Exit: CreateInsertDQ Method Enter: CreateInsertDQ Method Enter: CreateSingleTargetInsertDQ Generated Sql query: Query: INSERT INTO [ComponentDoc].[dbo].[Serial] ([Number], [CreatedById], [ChangedById]) VALUES (@Number, @CreatedById, @ChangedById);SELECT @Id=SCOPE_IDENTITY() Parameter: @Id : Int64. Length: 0. Precision: 19. Scale: 0. Direction: Output. Value: <undefined value>. Parameter: @Number : String. Length: 50. Precision: 0. Scale: 0. Direction: Input. Value: "jewes09". Parameter: @CreatedById : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 34888. Parameter: @ChangedById : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 34888.

Method Exit: CreateSingleTargetInsertDQ Method Exit: CreateInsertDQ Method Enter: CreateInsertDQ Method Enter: CreateSingleTargetInsertDQ Generated Sql query: Query: INSERT INTO [ComponentDoc].[dbo].[Serial] ([Number], [CreatedById], [ChangedById]) VALUES (@Number, @CreatedById, @ChangedById);SELECT @Id=SCOPE_IDENTITY() Parameter: @Id : Int64. Length: 0. Precision: 19. Scale: 0. Direction: Output. Value: <undefined value>. Parameter: @Number : String. Length: 50. Precision: 0. Scale: 0. Direction: Input. Value: "jewes08". Parameter: @CreatedById : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 34888. Parameter: @ChangedById : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 34888.

Method Exit: CreateSingleTargetInsertDQ Method Exit: CreateInsertDQ A first chance exception of type 'SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException' occurred in SD.LLBLGen.Pro.ORMSupportClasses.NET20.DLL The thread '<No Name>' (0x650) has exited with code 0 (0x0).

We have an idea, that this have to do with the async call and cache. But we do not know what to do. Cound anyone please advice.

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 11-Mar-2010 11:41:56   

Could you please post some code snippets.

Vestas
User
Posts: 6
Joined: 27-Jun-2008
# Posted on: 11-Mar-2010 12:59:59   

I'll love to put in some code, but it is prety complexed.

What I'll like to try is to either remove caching or cleaning the cache before im saving the collection. But im not quit sure how to do that.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 11-Mar-2010 21:09:59   

Which cache do you mean ?

Matt