Showing posts with label Assign an empty string if the value is null in Linq. Show all posts
Showing posts with label Assign an empty string if the value is null in Linq. Show all posts

Monday, October 14, 2024

Assign an empty string if the value is null in Linq

 If you ever wanted to assign an empty string to a value returned from a Linq query, use ?? (null-coalescing operator) to return Empty string in case of null


var qry= from row in context.Table

select new {  FieldValue = (field.Value ?? string.Empty) };


Cheers,

Samitha