ssteenkiste / nettiers

Automatically exported from code.google.com/p/nettiers
1 stars 0 forks source link

GetOriginalEntity method doesn't return TimeStamp properties values. #305

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Call the GetOriginalEntity method of an Entity who has a TimeStamp
property and this will be returned as null.

What is the expected output? What do you see instead?
The expected result is an entity object with the timestamp property
assigned if the _originalData is different from null. But this method is
returning a property equal to null unless the _originalData field
(variable) has been set and therefore different from null.

What version of .netTiers and CodeSmith are you using?
.netTiers 2.3.r803 (3/10/2009)  & CodeSmith 5.0.1.4983

Please provide any additional information below.

Original issue reported on code.google.com by elnoegar...@gmail.com on 29 Apr 2010 at 8:56

GoogleCodeExporter commented 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

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 21 Sep 2010 at 12:34

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 22 Sep 2010 at 9:34