.net - C# LINQ storing int? as int -
i querying database contractorid field value, either return 1 value or null. need pass integer onto class method(int,int). apparently not matching methods best overload. suspect because int?
contractorid value null , cannot converted integer. if remove ?
, use int error single()
method in linq
int userid = new bussinesscomponent().logindetails.userid; using (var db = new datacontext()) { int? contractorid = db .users .where(x => x.userid == userid) .select(x => x.contractorid) .single(); ltloj.text = dashboardcomponent.getjobs(userid,contractorid ).tostring(); }
indeed, need convert int?
int
because null cannot converted int.
you can using 'getvalueordefault()` give default value.
ltloj.text = dashboardcomponent.getjobs(userid, contractorid.getvalueordefault(0)) .tostring();
Comments
Post a Comment