开发者

Nullable Integer ? (working with linq)

开发者 https://www.devze.com 2022-12-23 16:23 出处:网络
I\'ve got exception about convert NULL to Int32. I\'ve got a table from database with nullable tinyint

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)

an开发者_开发百科d 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.


I don't know nemerle, but in C# you would make StatType a nullable integer (Nullable<int> aka int?) instead of a non-nullable one. That's the most logical solution - does nemerle support nullable value types?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号