I have a Win app that has EditableRootListBase<EditableRootListBase,BusinessBase> where if I am adding two rows(one after the other) with the same unique keys, one makes it ok but the second shows on the gui as being ok, does not make it into the db and throws no exception. If I add one first and then close and reload and then add another one with the same unique key, I am getting a unique db exception which is the right way. In summary, it seems that if EditableRootListBase has a list and then add another one with the same unique id, it does not throw an exception when moving to the next row in the win grid. Am I missing something?
GeorgeG:I have a Win app that has EditableRootListBase<EditableRootListBase,BusinessBase> where if I am adding two rows(one after the other) with the same unique keys
The table has a unique column based on values that the users are entering. It seems that we should change the schema to inlude some dummy id ie guid(ideal) or may be loop through all the list and see if its already there and throw an exception or something.
Thanks
Well this is an interesting issue though, because I am assuming there IS an exception on that second row. Assuming you aren't somehow suppressing it in your DP_Insert() method, I wonder where that exception is going?
In other words, the db obviously throws a duplicate key exception. DP_Insert() probably does nothing, so it flows back through the data portal and on the client appears as a DataPortalException from the Save() method of your root object.
ERLB doesn't catch that exception, so it would flow back to the UI - to data binding. So either data binding, or the grid control, must be catching and swallowing this exception.
My guess is that the grid is the culprit here, though I don't know for sure. I think, however, that in your UI you can handle a DataError event from the grid (or something like that), and you can cause the grid to actually show the error - or you can pop up a dialog or something along that line.
There is no error if you enter both rows one after the other which is what is happening here. When I enter the second row with the same user input ukey EndEdit goes up to GetObjectID and stops there and exists and row looks good on the grid. The row does not make in in the db and does not call the dp_insert method. There is code to handle the datagrid dataerror and show the error msg at the user but this is never being called.
I see. You may need to alter either your GetIdValue()
implementation or your Equals() implementation then.
One way or another, you need to ensure that each object can be
uniquely identified.
Remember that GetIdValue() is really only used by CSLA .NET
itself. You can have it provide any unique value you choose, as long as
it is unique. In many cases the simplest thing is to use a unique value in your
object’s data – but that isn’t always possible. In cases
where it isn’t possible, you may consider using an auto-incrementing int
counter or a GUID value.
The only thing you would likely need to change to avoid public
disclosure of your arbitrary value is ToString(), which returns the
GetIdValue() as a string. But people often override this anyway, because they
want to return something other than the primary key value to start with.
Alternately you could override Equals() and make it do some sort
of deeper comparison to ensure you uniquely identify each object. But my guess
is that the best approach is to change GetIdValue() to actually return a unique
value – that is the requirement for that method, and the fact that it isn’t
currently returning a unique value is the root of your problem.
Rocky
Copyright (c) Marimer LLC