Linq JOIN on a strongly typed dataset where comparator contains DbNull throws exception

0

Issue

Consider the query:

Dim orgs = From g In dbDS.gi_game
            Join o In dbDS.gi_organisation On g.DeveloperID Equals o.ID
            Select o

This will throw an exception when g.DeveloperID is DBNull (this is by design – changing DBNull to any other value is not an option):

System.Data.StrongTypingException: 'The value for column 'DeveloperID' in table 'gi_game' is DBNull.'

I tried this:

Dim orgs = From g In dbDS.gi_game
            Join o In dbDS.gi_organisation On g.DeveloperID Equals o.ID
            Where Not g.IsDeveloperIDNull
            Select o

But hit the same error upon the query enumeration. How do I control for dbnulls?

UPDATE:

Thanks to Shaybakov’s answer below, problem solved by mixing linq and lambda. vb.net code:

Dim orgs = From g In dbDS.gi_game.Where(Function(x) x.IsDeveloperIDNull = False)
            Join o In dbDS.gi_organisation On g.DeveloperID Equals o.ID
            Select o

Solution

c# syntax

From g In dbDS.gi_game.Where(x=>!x.IsDeveloperIDNull())
        Join o In dbDS.gi_organisation On g.DeveloperID Equals o.ID
        Select o

Answered By – Shaybakov

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More