tags:

views:

328

answers:

3

I get my object from the database using my repo like this:

Public Shared Function GetOrderFulfillment(ByVal OrderNumber As Integer) As OrderFulfillment
  Dim objCustomerOrder = DB.Select().From(Tables.OrderFulfillment).Where(Columns.OrderNumber).IsEqualTo(OrderNumber).ExecuteSingle(Of OrderFulfillment)()
  objCustomerOrder.MarkOld()
  Return objCustomerOrder
End Function

Change some values and save it back:

orderFulfillment.OrderTotal = newOrderTotal + netShipping + netTax
        orderFulfillment.TotalShippingCost = netShipping
        orderFulfillment.Tax = netTax
        orderFulfillment.AutoShipDiscount = order.AutoShipDiscount * -1
        orderFulfillment.Shipping = totalShipping 
        orderFulfillment.RefundAmount = totalRefundAmount
        orderFulfillment.ActualShippingCost = ActualCost
        orderFulfillment.HandlingFee = HandlingFee
        orderFulfillment.Save("AutomatedUpdateOrderStatus")

This generates the following SQL that fails for obvious reasons:

exec sp_executesql N'UPDATE [ultrawellness].[OrderFulfillment] SET  WHERE [OrderFulfillmentID] = @OrderFulfillmentID; SELECT @OrderFulfillmentID AS id',N'@OrderFulfillmentID int',@OrderFulfillmentID=7055

Where in the world are my SET values at? I have used this same pattern a millinon times - why is it chocking on this one?

FYI on the object that I apply the save to the following is set: .IsDirty = True .DirtyColumns = 0

I think DirtyColumns should not be 0 since I updated a bunch of them but that is just a guess?

Anyone?

+1  A: 

Could it be that your shared method doesn't return an existing record, because the query don't match a row? In that case objCustomerOrder is a new object.

Check objCustomerOrder.IsLoaded to be sure.

If you have a new Object and call MarkOld() on it, that could cause the problem.

I would suggest to not use MarkOld in this situation, because SubSonic is clever enought to handle it correctly (unless you explicitly want to set a new object to old)

SchlaWiener
for some reason in VB.Net Dim objCustomerOrder = DB.Select().From(Tables.OrderFulfillment).Where(Columns.OrderNumber).IsEqualTo(OrderNumber).ExecuteSingle(Of OrderFulfillment)() results in .IsNew being true even if it's an existing record so I have to MarkOld()
Slee
Can't confirm that in my project (currently 2.2 @ r523 + some patches, but non related to IsNew beeing set false).
SchlaWiener
A: 

I changed my code to get the object to:

  Dim objCustomerOrder = New Model.OrderFulfillment("OrderNumber", OrderNumber)

This solved both my .IsNew problem as well as my saving problem.

Slee
+2  A: 

The first query is just that - a query and is not part of the ActiveRecord "system" if you will. In other words we have no idea where that object came from.

But if you do as you did with your example above (calling new Object()) then we know you pulled an existing record and we can track its changes.

Rob Conery
thanks for the clarification!
Slee