I have learned the hard way to always refetch after persisting anything in the adapter scenario. I already read and understood Frans' explanation of why to do this, but without really thinking about it I was cutting a corner and it caused me some grief, though I am not sure why, but refetching solved the problem.
I've got a Janus ASP.NET grid. After adding a record, the grid would act really goofy. Let's say I add one record. It's a PO line item that is numbered 1 by my code. After the save, I would have 3 rows - first row has the line number 1, second has the remaining fields, and the 3rd row was ready for new input. Of course rows 1 and 2 here should just be the same. In the appropriate event handler for the grid I was doing this:
EntityCollection details = po.PODetail;
PODetailEntity detail = new PODetailEntity();
GridEXCellCollection cells = e.Row.Cells;
try
{
detail.PONumber = po.PONumber;
detail.POLineNumber = (short)(details.Count + 1);
detail.Item = cells["Item"].Text;
detail.AcctID = cells["AcctID"].Text;
detail.Quantity = (float)(double)cells["Quantity"].Value;
detail.UOMID = (int)cells["UOMID"].Value;
detail.Price = (float)(double)cells["Price"].Value;
detail.TaxRate = (float)(double)cells["TaxRate"].Value;
if (cells["QuoteReference"].Text != "")
detail.QuoteReference = cells["QuoteReference"].Text;
mgr.SaveDetail(detail);
details.Add(detail);
I was attempting to cut a little corner by just adding the new line item directly to my collection. Replacing
details.Add(detail);
with
mgr.FetchPO(po.PONumber);
magically solved my problem, though like I said, I don't know why. The details collection (which I rebind in another event handler) has the right count, so this seemed like a harmless thing to do.
Maybe this post will save someone else a few hours.