Left outer join null using VB.NET and LINQ -
Left outer join null using VB.NET and LINQ -
i've got think working left outer bring together linq query, i'm having problems select because of null values in right hand side of join. here have far
dim os = e in oexcel grouping bring together c in oclassindexs on c.tclasscode equals mid(e.classcode, 1, 4) right1 = grouping _ c in right1.defaultifempty
i want homecoming of e
, 1 column c
called tclasscode
. wondering syntax be. can see, i'm using vb.net.
here query doing bring together error:
_message = "object reference not set instance of object."
dim os = e in oexcel grouping bring together c in oclassindexs on c.tclasscode equals mid(e.classcode, 1, 4) right1 = grouping _ c in right1.defaultifempty select e, c.tclasscode
if remove c.tclasscode select, query runs without error. thought perhaps needed select new, don't think doing correctly either.
edit: need check c
null, c
after grouping. see updates below.
you need null check on tclasscode
c
in select statement. what type tclasscode
? should able null check on the value c
, if it's null cast nullable of respective type , returned it, otherwise homecoming actual value.
since not sure tclasscode
let's assume it's integer, in case cast nullable integer (integer?
). in mind select statement, added @ end of have far, should resemble:
since tclasscode
string code resemble:
select _ e, _ code = if(c nothing, nothing, c.tclasscode)
depending on need if c
null homecoming string.empty
instead of nothing
:
select _ e, _ code = if(c nothing, string.empty, c.tclasscode)
of course of study free farther expand selection of "e" project specific columns name.
the of import thing realize must check c
null before using of properties since might null depending on left outer bring together result particular result (row). before example, if had field named priority
integer cast against nullable:
select _ e, _ priority = if(c nothing, ctype(nothing, integer?), c.priority)
vb.net linq left-join
Comments
Post a Comment