AnantLabs / codesmith

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

CSLA: with version fields ChildUpdate.ParametrizedSQL cause runtime exception because reader("anyvariable") are not found #479

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The ChildUpdate with ParametrizedSQL (when you use version field) are causing 
an exception because reader(“anyvariable”) are not found.

It seem as if the issue was fixed in storedprocedures and is out of synch at 
parametrizedsql.

The change that fix it is below:

The line 41 in 
http://code.google.com/p/codesmith/source/browse/trunk/Templates/Frameworks/Csla
/VisualBasic/Common/ChildUpdate.ParameterizedSQL.cst :
LoadProperty(<%= member.PrivateMemberVariableName %>Property, <%If not 
[member].HasByteArrayColumn() Then %>reader.<%= [member].GetReaderMethod() 
%>("<%= [member].ColumnName %>")<% else %>ADOHelper.GetBytes(reader, "<%= 
member.ColumnName %>")<% End If %>)
<% End If

Must be changed and must be the same as line 44 of 
http://code.google.com/p/codesmith/source/browse/trunk/Templates/Frameworks/Csla
/VisualBasic/Common/ChildUpdate.StoredProcedures.cst :
LoadProperty(<%= member.PrivateMemberVariableName %>Property, 
DirectCast(command.Parameters("<%= member.BuildParameterVariableName() 
%>").Value, <%= member.SystemType %>))

What version of the product are you using?
CSLA-v3.0.0.1887

Please provide any additional information below.
I attached a complete simple project with unit test and database schema.
If you see, when you use a version field the update sql end with the retrieval 
of the version product, and then the 
reader.GetInt32(“anyfieldminusversionfield”) always cause an exception 
because "anyfieldminusversionfield" are not retrieved in sql.

Sample code generated
---------------------------------------------------------------------
Const commandText As String = "UPDATE [dbo].[Commissions]  SET [idProduct] = 
@p_idProduct, [idAgent] = @p_idAgent, [commission] = @p_commission WHERE 
[idProduct] = @p_OriginalidProduct AND [idAgent] = @p_OriginalidAgent AND 
[version] = @p_version; SELECT [version] FROM [dbo].[Commissions] WHERE 
idProduct = @p_idProduct"
            Using command As New SqlCommand(commandText, connection)
                command.Parameters.AddWithValue("@p_OriginalidProduct", Me.OriginalIdProduct)
                           command.Parameters.AddWithValue("@p_idProduct", Me.IdProduct)
                           command.Parameters.AddWithValue("@p_OriginalidAgent", Me.OriginalIdAgent)
                           command.Parameters.AddWithValue("@p_idAgent", Me.IdAgent)
                           command.Parameters.AddWithValue("@p_commission", Me.CommissionMember)
                command.Parameters.AddWithValue("@p_version", SqlDbType.Timestamp)
                command.Parameters("@p_version").Value = Me.Version
                command.Parameters("@p_version").Direction = ParameterDirection.InputOutput

                Using reader As SafeDataReader = New SafeDataReader(command.ExecuteReader())
                    If reader.Read() Then
                        Version = ADOHelper.GetBytes(reader, "version")
                        ' Update non-identity primary key value.
                        LoadProperty(_idProductProperty, reader.GetInt32("idProduct"))
---------------------------------------------------------------------

The last sentence LoadProperty(_idProductProperty, 
reader.GetInt32("idProduct")) cause an exception.

Original issue reported on code.google.com by bernyrod...@gmail.com on 5 Aug 2010 at 3:36

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 5 Aug 2010 at 4:15

GoogleCodeExporter commented 9 years ago
Hello,

Thanks for the sample. I'll take a look into this issue.

Thanks
-Blake Niemyjski

Original comment by bniemyjski on 17 Aug 2010 at 10:34

GoogleCodeExporter commented 9 years ago
This issue was updated by revision r1922.

fixed Issue 479:    CSLA: with version fields ChildUpdate.ParametrizedSQL cause 
runtime exception because reader("anyvariable") are not found

Original comment by bniemyjski on 24 Aug 2010 at 6:38

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 24 Aug 2010 at 6:38