cannot convert from 'int?' to 'int' in LLBLGen2.0

Posts   
 
    
sbalaji123
User
Posts: 26
Joined: 13-Oct-2006
# Posted on: 13-Oct-2006 16:46:50   

Hi, I am using LLBLGen2.0.My desinger is havinh selfservicetwoclasses.Software ASP.NET2.0,SQLServer2005 and VStudio2005.When i migrate from 1.0 to 2.0 then i got lots of conversion error in my projests. For ex: cannot convert from 'int?' to 'int' in LLBLGen2.0

How can i go about this?

Thanks in advance, Balaji

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 14-Oct-2006 02:28:13   

Please read the section of the manual that speaks about the upgrade from 1.0 to 2.0. If you have nullable fields which map to a value then you have this error occur.

.NET 2.0: nullable fields which are read into normal value types will cause non-compilable code. If you're migrating your code to .NET 2.0, you either have to do: (example)


// C#
Nullable<int> someValue = myEntity.FieldName;
' VB.NET 2005
Dim someValue As Nullable(of Integer) = myEntity.FieldName

or do something like:

// C#
int someValue = myEntity.FieldName.Value;
' VB.NET 2005
Dim someValue As Integer = myEntity.FieldName

The second option runs the risk of an exception at runtime. To avoid that do:

// C#
if(myEntity.Field.HasValue)
{
    int someValue = myEntity.Field.Value;
}
' VB.NET 2005
If myEntity.Field.HasValue Then
    Dim someValue As Integer = myEntity.Field.Value
End If