none
Check for not null values

    Question

  •      

    Hi,

    I have the below query which will fetch records from 'RegistrationMessages' table.

    var query = from bytRegistrations in _context.RegistrationMessages
                            select new RegistrationGridViewData
                            {
                                Wwid = bytRegistrations.WWID,
                                Employee = bytRegistrations.Domain + "/" + bytRegistrations.Account + "  [ " + bytRegistrations.User + " ]",
                                DeviceMac = bytRegistrations.MacAddress,
                                GpsLatitude = bytRegistrations.GpsLatitude.ToString(),
                                GpsLongitude = bytRegistrations.GpsLongitude.ToString(),
                                Location = bytRegistrations.City.ToString() + ", " + bytRegistrations.Country.ToString()
                            };

    I want to set 'Location' value with som default value(say "NoLocation') if the table does not contain the values(null, empty) for columns 'City' or 'Country'...

    How I can alter this query to do that?

    Please help me!

    Tuesday, July 16, 2013 8:51 AM

Answers

  • Location = ((bytRegistrations.City == null || bytRegistrations.City.Equals("")) && 
    			(bytRegistrations.Country == null || bytRegistrations.Country.Equals(""))) 
    			? "NoLocation"
    			: bytRegistrations.City + ", " + bytRegistrations.Country
    


    Please Mark as Answer and Vote as Helpful if I helped.

    Also please visit my blog http://www.msguy.me/


    Tuesday, July 16, 2013 9:36 AM