none
select new and nulls RRS feed

  • Question

  •  

    i have a linq query for example

     

    var bookings = from b in bookings

    where b.ID = 10

    selct new { b.ID, b.Name, b.Item.Description}

     

     

    works fine until there is no Item for the particular booking and then throws an exception, how do i make it put the description into the result if it exists but null string if it doesnt

     

     

    thanks

    kmv

     

    Monday, March 31, 2008 10:16 AM

Answers

  • Hi,

     

    I would try (I haven't tested this)

    var bookings = from b in bookings

    where b.ID = 10

    selct new { b.ID, b.Name, Description = (b.Item != null) ? b.Item.Description : string.Empty}

     

    regards

    Philipp

    Monday, March 31, 2008 11:23 AM

All replies

  • Hi,

     

    I would try (I haven't tested this)

    var bookings = from b in bookings

    where b.ID = 10

    selct new { b.ID, b.Name, Description = (b.Item != null) ? b.Item.Description : string.Empty}

     

    regards

    Philipp

    Monday, March 31, 2008 11:23 AM
  • thanks

     

     

    that got it

     

     

    KMV

     

    Tuesday, April 1, 2008 9:16 AM