Otis wrote:
Is there a delete query generated for the order entity? It should be deleted. Or is it a new entity? (e.g. IsNew is true)
Bulls-eye. It was actually a new instance of the Orders object.. Thanks man
Otis wrote:
You mean that 'OrderDetailsEntity' name?
Yes. It came to me that I can write my TDL template to generate this code for me.
OK.. seems I spoke too soon. Now I am getting the following exception
An exception was caught during the execution of an action query: DELETE statement conflicted with COLUMN REFERENCE constraint 'FK_Order_Details_Orders'. The conflict occurred in database 'NorthwindJCL', table 'Order Details', column 'OrderID'.
The statement has been terminated.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.
Parameters Values:
@OrderID1=11080
Query: DELETE FROM [NorthwindJCL].[dbo].[Orders] WHERE ( [NorthwindJCL].[dbo].[Orders].[OrderID] = @OrderID1)
Parameter: @OrderID1 : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 11080.
When I turned tracing ON, the generated SQL query showed
Generated Sql query:
Query: DELETE FROM [NorthwindJCL].[dbo].[Orders] WHERE ( [NorthwindJCL].[dbo].[Orders].[OrderID] = @OrderID1)
Parameter: @OrderID1 : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 11080.
I don't know why now it generates SQL query for the primary entity (Orders) and does NOT generate any SQL query for the related entity (OrdersDetails).
This is the code being executed (in the Orders class)
adapter = BL.DataAccessAdapterFactory.CreateDataAccessadapter(True)
adapter.StartTransaction(IsolationLevel.RepeatableRead, "DeleteOrdersEntity " & Me.ToString)
Me.IsNew = False
Me.OrderID = crit.OrderID 'get PK field value
Dim uow As UnitOfWork2 = New UnitOfWork2
uow.AddDeleteEntitiesDirectlyCall("OrderDetailsEntity", Me.GetRelationInfoOrderDetailsCollection())
uow.AddForDelete(Me) 'delete the Order entity
uow.Commit(adapter, True)
adapter.CloseConnection()