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!


Robert Linton
Robert Linton
StrataFrame Beginner (21 reputation)StrataFrame Beginner (21 reputation)StrataFrame Beginner (21 reputation)StrataFrame Beginner (21 reputation)StrataFrame Beginner (21 reputation)StrataFrame Beginner (21 reputation)StrataFrame Beginner (21 reputation)StrataFrame Beginner (21 reputation)StrataFrame Beginner (21 reputation)
Group: Forum Members
Posts: 13, Visits: 49
Hi Kevin,

Any value type, including struct can be nullable: Except reference types. Strings are reference types so you can configure your BO string types as nullable.

I'm new to SF...so this may not be entirely correct, but I've been using the "replace..." option and returning a " " instead.

Hope that helps,

Rob

Robert Linton
Robert Linton
StrataFrame Beginner (21 reputation)StrataFrame Beginner (21 reputation)StrataFrame Beginner (21 reputation)StrataFrame Beginner (21 reputation)StrataFrame Beginner (21 reputation)StrataFrame Beginner (21 reputation)StrataFrame Beginner (21 reputation)StrataFrame Beginner (21 reputation)StrataFrame Beginner (21 reputation)
Group: Forum Members
Posts: 13, Visits: 49
Error in above post...

String are reference types so you can not assign them as nullable

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: ""

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
Sounds good. What's the advantage of using the nullable generic type then?
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
Really the same concept of any other type of generic...saving time when applicable without having to explicitly define a specific class or value while remaining strong-typed.  That is why they are dubbed "generics"...the same class can be used interchangably for different value types. 
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