Linq to Sql and Child_OnDataPortalInvokeComplete

Linq to Sql and Child_OnDataPortalInvokeComplete

Old forum URL: forums.lhotka.net/forums/t/6836.aspx


ajj3085 posted on Wednesday, April 22, 2009

HI,

I have a bug I'm trying to fix, but I'm not sure about the best way.

I have a BO that is a bit different; it always exists, even if there's no corrisponding row in the database. The logic is that every product appears on a price list all the time, and some prices are calculated, not stored. Anyway, I've been handling this by overriding Child_OnDataPortalInvokeComplete and setting the state appropriately. That is, New but Clean if no corrisponding row exists, Old if one does, and on deletion resetting to New and Clean. Things have been working well, but a bug has shown up in a particular situation.

The problem is introducing linq; since Child_OnDataPortalInvokeComplete only has an Update status, no Insert or Delete, I was looking at the primary key field (which the object stores) to determine what state to set the object in.. either Old or New and Clean. Now that Linq is in the picture, Child_OnDataPortalInvokeComplete is called BEFORE the call to SubmitChanges, so the object is being put into an bad state if the object was New and Clean... it's set back to New and Clean again.

I'm not really sure where to move this code anymore.. the main problem being that I can't keep it where it is, and with Linq I have no way of knowing when the deletion was actually performed. For Inserts, I can listen to the PropertyChanged event for the primary key, but I don't see anyway to get the actual deletion from linq.

Any ideas?

ajj3085 replied on Thursday, April 23, 2009

Well, what I did was add a field, wasDeleted, and it's set only when the instance was "deleted." When the instance is deserialized, I set the flag to false and call MarkNew and MarkClean. The Insert and Update MarkOld is now called by the child dataportal, so those states are correct.

So, unless anyone has a better option (OnDeserialized feels like a hack), I guess this is what I'll do.

Copyright (c) Marimer LLC