Nullable Integer ? (working with linq)

Posted by nCdy on Stack Overflow See other posts from Stack Overflow or by nCdy
Published on 2010-03-23T09:40:45Z Indexed on 2010/03/23 9:43 UTC
Read the original article Hit count: 389

Filed under:
|
|
|

I've got exception about convert NULL to Int32.

I've got a table from database with nullable tinyint

    [Column(Storage="_StatType", DbType="tinyint NULL")]
    public StatType : int { get { _StatType; } }

(to get C# code just replace variable's type)

and after making linq select

                def StartLinq = linq <#from lpi in _CfgListParIzm
                    where lpi.ID_ListParIzm==drr1
                    select (lpi.StatType)
                #> ;

StartLinq.ToArray()[0] can't be readed if that is null :-/

                    mutable STT : int = 0;
                    try
                    {
                        _=int.TryParse(StartLinq.ToArray()[0].ToString(), out STT);
                    }
                    catch { | _ is Exception => () /* I don't care*/ }

upper code is very poor trick :( I wont use it.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET