This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I have a parent child (many to one) relationship between a PO table, and a Purchasing Rules table. In the form code I obtain the corret PurchaingRule entity based on order value etc. The try to set the correct field in the PO to this entity. The code is as below. var pl = Stock.GetPurchasingRule(invValue); //Returns PurchashingRule Entity. The probem is that the _po.PurchasingRule = pl; only seems to work about one time in 5, the remainder of the time, _po.PurchasingRule still contains it's previous value. If I step though the code often on the first attempt it will not accept the value, but no error is throwm, but then if I stop the code and set that line to be the next statement, without changing anything, this time it will accept the value. I find this all to be very confusing, I hope you can suggest where I am going wrong.
|
|
|
I find this very confusing too -- I am pretty sure that must be a bug, and I find it hard to imagine why it would work intermittently rather than always or never. The only thing I can suggest is that it looks like pl may be part of a different unit of work from _po (since _po is being attached to a newly created UOW). Could you try attaching pl to the same UOW before setting _po.PurchasingRule? If that doesn't help then is it possible for you to provide us with a minimal repro program so we can investigate a fix? Thanks! |
|
|
Hi Ivan, The uow in both cases is created from the same static context, would that make it a different uow or the same? Also, as a work around, I found that if I assign a value of null to _po.PurchasingRule first, then in the next line of code assign the required value, it works 100% of the time. Not sure if this helps or confuses more. Thanks Mark |
|
|
I think it would still be a different UOW, if only because you're assigning _po to a UOW that has only just been created. Creating from the same static context doesn't matter -- think of a UOW as a connection (or transaction) and a context as a connection string -- the two UOWs are talking to the same database in the same way, but once created they're completely separate. The info about nulling helps, I think (!) -- this is beginning to sound like a bit like a lazy/eager load bug. Can you let me know whether the association is lazy or eager loaded? Also, could you try calling uow.Attach(pl) before assigning the association, and let me know if that makes any difference? Thanks! Are you okay to use the nulling-out workaround for the time being? |
|
|
Hi Ivan, The PurchasingRules are Eager loaded. I have Attached the _po before trying to set it, the results were the same. I am okay with the null workaround for the moment, but obviously would like to set it correctly eventually. Many thanks Mark |
|