check null in where clause in LINQ RRS feed

  • Question

  • Hi,

    Can anyone please tell me how to check null in the where clause of a LINQ query

    I want to display the first name of all the users having photos

    Below is my code,



    u in DataClasses1.TBL_USERs


    where USER_PHOTO != null

    select u.FIRST_NAME

    Datatype of USER_PHOTO is varbinary(max)

    Tuesday, October 27, 2009 10:15 AM


  • You were almost there - you need to reference USER_PHOTO using the "u" variable you specified previously, like so:

    var results = from u in DataClasses1.TBL_USERs
                  where u.USER_PHOTO != null
                  select u.FIRST_NAME;

    This will return an IEnumerable<string> (if FIRST_NAME is of type string), listing all of the first names of the users.
    Reed Copsey, Jr. - http://reedcopsey.com
    Tuesday, October 27, 2009 3:54 PM