AnantLabs / codesmith

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

EditableRoot.DataAccess.StoredProcedures.cst doesn't handle Nullable(of T) for parameters #273

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In VB templates if you have a nullable (of T) property the following code
lines will fail with an error like. "DataPortal.Update failed
(System.Data.SqlClient.SqlException: Procedure or function
'sp_Consultant_Insert' expects parameter '@pConsultLastUpdate', which was
not supplied."

EditableRoot.DataAccess.StoredProcedures.cst

Eg
command.Parameters.AddWithValue("@pConsultLastUpdated", Me.LastUpdatedDate)

Where Me.LastUpdatedDate = nothing.

What is the expected output? What do you see instead?
If Me.LastUpdatedDate.HasValue Then
 command.Parameters.AddWithValue("@pConsultLastUpdated", Me.LastUpdatedDate)
Else
 command.Parameters.AddWithValue("@pConsultLastUpdated", DBNull.Value)
End If

Please use labels and text to provide additional information.
SVN Revision 1415

Original issue reported on code.google.com by JenasysD...@gmail.com on 22 Feb 2010 at 6:59

GoogleCodeExporter commented 9 years ago
Blake,
I think this is a hang over from CSLA smart dates Nullable(of T) change. It 
applies
to Insert and Update Stored procedure statements.

You have code in the BuildCommandParameters functions that should apply to any
property that is nullable.  See
Templates\Frameworks\Csla\Source\CodeSmith.SchemaHelper.VisualBasicExtensions\Me
mberCollectionExtensions.cs
about line 124. I think it should be just a case of using the string format

If Member.Isnullable
{
cast = string.Format("IIf({0}{1}.HasValue, DirectCast({0}{1}.Value, {2}),
System.DBNull.Value))", castPrefix, propertyName,member.DataType);
}
Else
{
// cast = //All your normal code here.
}

Excuse my C# syntax.

Original comment by JenasysD...@gmail.com on 22 Feb 2010 at 10:14

GoogleCodeExporter commented 9 years ago
Blake,

Private Sub Map(ByVal reader As SafeDataReader) Also incorrectly reads Null 
data into
the properties. This is particularly problematic with nullable dates.

Eg. LoadProperty(_lastUpdatedDateProperty, 
reader.GetDateTime("ConsultLastUpdated"))
If reader.Item("ConsultLastUpdated") = Nothing then the 
GetProperty(lastUpdatedDateProperty).HasValue = True and .Value = "#12:00:00 
AM#"
which is commpletely incorrect.

If you create a Nunit test to Save a new record, then retrieve that record and 
try
and update a different field the SP will fallover with Exception:.

  ----> Csla.Reflection.CallMethodException : DataPortal_Update method call failed
  ----> System.Data.SqlTypes.SqlTypeException : SqlDateTime overflow. Must be between
1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

Original comment by JenasysD...@gmail.com on 22 Feb 2010 at 10:55

GoogleCodeExporter commented 9 years ago
I've done a unit test if you use the following sytax the nullable property loads
correctly.

LoadProperty(_lastUpdatedDateProperty, reader.Item("ConsultLastUpdated"))

The Csla.SafeDataReader.Get* methods are incorrectly converting the data to 
"safe"
values in the Private Sub Map(ByVal reader As SafeDataReader) code.

\Templates\Frameworks\Csla\VisualBasic\Common\MapDataReader.cst

Suggested change attached

Original comment by JenasysD...@gmail.com on 22 Feb 2010 at 11:16

GoogleCodeExporter commented 9 years ago
Hello,

This has been fixed in the latest nightly build.

Thanks
-Blake Niemyjski

Original comment by bniemyjski on 23 Feb 2010 at 12:50

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 23 Feb 2010 at 11:31

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 15 Jul 2010 at 2:21