AnantLabs / codesmith

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

CSLA Concurrency implementation avoids data to be updated #515

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Create a Table with a timestamp field
2.Generate an Entity using CSLA Templates
3.Create a Silverlight User interface and Bind it to the Entity
4.Make a Call to Get<Entity>By<Key>Async to get the 1 record from the table
5.Update any value using the UI and try to save changes (BeginSave)

What is the expected output? What do you see instead?
The expected output is an updated record... But I got a DBConcurrencyException

What version of the product are you using?
5.2

Please provide any additional information below.

IMO the timestamp value of the entity should be serialized back and forth so 
when DataPortal_Update gets called, the original timestamp is sent to SQL 
Server to be compared with it's current value... Heres is the sequence of 
actions:

SERVER SIDE

========================================================================

1.- The object is created on Server side by a Factory Method

2.- The Dataportal create a new instance of the business object via 
DataPortal_Create

3.- By declaration, timestamp gets an empty Byte(8) value

4.- DataPortal_Fetch Occurs

5.- timestamp gets current record value... let's say { 0,0,0,0,0,0,22,15}

6.- The object gets serialized by DataPortal WITHOUT timestamp because it's a 
private field

7.- Serialized Data goes through WCF service to the SL Client

CLIENT SIDE
========================================================================

8.- A silverlight instance of the business object is created By csla (CLIENT 
SIDE) via DataPortal_Create

9.- By declaration, timestamp gets an empty Byte(8) value

10.- Properties Gets loaded into the newly created Business Object from 
deserialized Data

11.- Default value for timestamp is not being replaced, so it stiil being 
Byte(8)

12.- User change some properties And Click Save Button

13.- Data Gets Serialized And sent to Server through WCF

SERVER SIDE (AGAIN)
=======================================================================

14.- The object is created on Server side by a Factory Method

15.- The Dataportal create a new instance of the business object via 
DataPortal_Create

16.- By declaration, timestamp gets an empty Byte(8) value {0,0,0,0,0,0,0,0}

17.- Deserialization occurs, all properties values get replaced EXCEPT timestamp

18.- Since default value for timestamp is not being replaced, it stiil being an 
Empty Byte(8)

19.- Dataportal_Update Gets Called

20.- The parameters collections is created and timestamp parameter gets Empty 
Byte(8)

21.- SqlCommand is executed with the trick of the where clausule that compares 
the parameter value of timestamp{ 0,0,0,0,0,0,0,0}  with {0,0,0,0,0,0,22,15} 
stored in SQL... off course they don't match so nothing gets updated and 
DBConcurrencyException is thrown

Original issue reported on code.google.com by jeanpaul...@gmail.com on 7 Oct 2010 at 1:10

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 7 Oct 2010 at 4:01

GoogleCodeExporter commented 9 years ago
I forgot to mention that as a workaround for this issue I put this code un in 
my Afiliacion.vb:

        Protected Overrides Sub OnSetState(ByVal info As Csla.Serialization.Mobile.SerializationInfo, ByVal mode As Csla.Core.StateMode)
            MyBase.OnSetState(info, mode)
            MarcadeTiempo = info.GetValue(Of System.Byte())("MarcadeTiempo")
        End Sub

        Protected Overrides Sub OnGetState(ByVal info As Csla.Serialization.Mobile.SerializationInfo, ByVal mode As Csla.Core.StateMode)
            MyBase.OnGetState(info, mode)
            info.AddValue("MarcadeTiempo", Me.MarcadeTiempo)
        End Sub

That made it work.

Original comment by jeanpaul...@gmail.com on 7 Oct 2010 at 4:36

GoogleCodeExporter commented 9 years ago
Hello,

Thanks for your work around. I'm going to mark this as investigating. It might 
make it into this next release.

Original comment by bniemyjski on 13 Mar 2012 at 4:27

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 13 Mar 2012 at 4:27