Open GoogleCodeExporter opened 9 years ago
I believe the problem lies more in teh Equality of 2 entities more than the the
GetOriginalEntity method returning the TimeStamp. I think the TimeStamp is
returned
but the Equals doesn't.
If I am right, we should rename the issue.
Original comment by jmhin...@gmail.com
on 30 Apr 2010 at 2:32
Original comment by bniemyjski
on 21 Sep 2010 at 12:34
Ok...
Let's say you have an object like an Invoice previously added to your DB and
this Invoice has an Id equal to 1.
Now let's say that you try to add another Invoice with the same Id (1), but the
other properties are different from the already saved.
As is known, to perform this kind of validation with Nettiers you have to
create a "Processor" in which you should code something like this (inside the
processor):
private bool IDValidator(object target, ValidationRuleArgs e)
{
InvoiceService invoiceService = new InvoiceService();
Invoice oInvoice = invoiceService.GetByInvoiceId(_invoice.InvoiceId);
if (oInvoice != null) // if we get an object...
{
if (_invoice.EntityState == EntityState.Added) // and if it's a new object
{
e.Description = "The ID is duplicated...";
return false;
}
else // but, if it's an update...
{
// and it's not the object previously added to the DB.
// You MUST do something like:
if (!oInvoice.StampField.Equals(_invoice.GetOriginalEntity().StampField))
{
e.Description = string.Format("The ID is duplicated";
return false;
}
}
}
return true; // if you get here at runtime, the object is OK.
}
As I said, if you try to add a new object with an already existing ID, the
Validation (in the processor) throws the corresponding exception and add the
result to the BrokenRulesList.
Till here, everything's fine because it was a NEW object with a duplicated ID
which you tried to add to the DB. But...as always for us, there is a "but"...
knowing that there are fool people in the world and that many of them are our
co-workers and knowing too that sometimes in real world you desing an Object
Library but others design the User Interface.... we have to prevent that the UI
programmer (or ourselves) forgets to block the ID to be modified when the end
user "edits" an existing object, and the end user modifies an EXISTING object
in the DB with the same data of another existing object in the DB.
Here's the point in question. The code in the "else" section of the function
IDValidator is reached and the Equals method can't check if the TimeStamp field
is the same 'couse the GetOriginalEntity method doesn't return the timestamps
values. So how can we know that this "edited" object is not the previously
added to the DB with the same ID?
What I did, because nothing else came to my mind, was to change the line which
calls the Equals method for the next line:
if (!oInvoice.GetOriginalEntity().Equals(_invoice.GetOriginalEntity()))
This way no timestamps are returned or compared and if the edited object is the
same on the DB, no exception is generated.
This works for me, and I don't know certainly if it's really a problem with the
GetOriginalEntity method that doesn't return the timestamp values of the object
or if there's a problem with the "Equals" method that doesn't know how to
compare timestamp values or if it's a problem in both of them. But I know that
I found a workaround to the problem which can be used till the problem be
solved. I don't solve it because sincerelly I don't understand how to do it :s
I'm sorry for the extension of the message, but I guess this is the info that
is needed to reproduce the problem that I found.
Best regards...
Noe
Original comment by elnoegar...@gmail.com
on 21 Sep 2010 at 10:57
Original comment by bniemyjski
on 22 Sep 2010 at 9:34
Original issue reported on code.google.com by
elnoegar...@gmail.com
on 29 Apr 2010 at 8:56