Using Nullable in BO


Author
Message
Kevin Lingofelter
Kevin Lingofelter
StrataFrame Novice (123 reputation)StrataFrame Novice (123 reputation)StrataFrame Novice (123 reputation)StrataFrame Novice (123 reputation)StrataFrame Novice (123 reputation)StrataFrame Novice (123 reputation)StrataFrame Novice (123 reputation)StrataFrame Novice (123 reputation)StrataFrame Novice (123 reputation)
Group: Forum Members
Posts: 77, Visits: 804
Hello All!

I am setting up some fields in the mapper to Use Nullable Generic. This setting works ok if the field is a numeric type, but if the field is varchar, the code the mapper generates is causing the build to fail. Here is the code for the field:

''' <summary>
''' Test
''' </summary>
''' <remarks></remarks>
<Browsable(False), _
BusinessFieldDisplayInEditor(), _
Description(
"Test"), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
Public Property [Test]() As Nullable(Of System.String)
  Get
    Dim loValue As Object
    loValue = Me.CurrentRow.Item("Test")
   
If loValue Is DBNull.Value Then
       
Return CType(Nothing, Nullable(Of System.String))
   
Else
       
Return CType(loValue, Nullable(Of System.String))
   
End If
 
End Get
 
Set(ByVal value As Nullable(Of System.String))
   
If value.HasValue Then
     
Me.CurrentRow.Item("Test") = value.Value
   
Else
     
Me.CurrentRow.Item("Test") = DBNull.Value
   
End If
 
End Set
End Property

The hilighted code is giving the error:

Error 1 Type argument 'String' does not satisfy the 'Structure' constraint for type parameter 'T' ...

Anyone know why this is? Thanks!


Reply
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Kevin,

Only structure data types support a generic nullable, and a string is not a structure data type.  To determine what does and does not support a nullable generic, you can reference the object browse and look at the inheritance.  Anything that inherits from a System.ValueType can be used with a nullable generic.  Here is the rule of thumb, if Nothing or NULL can be assigned to it, it does not support a nullable generic.

When nullable generic is not supported, use Return Alternate on NULL option for the field and specify the exact text below that should be returned.  For example, if you want to return an empty string, enter the following value: ""

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search