Q:

default values in LINQ query

I have following Linq query/function in my MVC3 application. 
public AuditTrail GetNamesAddressesEmployers(long registryId , int changedField) {
    var otherNameAndAddress = (from a in context.AuditTrails
                               where a.ChangedField == changedField
                                  && a.RegistryId == registryId
                               select a).FirstOrDefault();
    return otherNameAndAddress;   
} 

I want that if otherNameAndAddress = null then its properties should be assigned some values.
otherNameAndAddress has Name and description property. This GetNamesAddressesEmployers is being used at 3 places. I want to assign different values to name and description when otherNameAndAddress  = null at all three locations.

A:

You're already using FirstOrDefault() so why not specify the Default:
public AuditTrail GetNamesAddressesEmployers(long registryId, int changedField)
{
    return context.AuditTrails            
        .Where(a => a.ChangedField == changedField 
             && a.RegistryId == registryId)
        .DefaultIfEmpty(new AuditTrail { /* fill properties here */ })
        .FirstOrDefault();
}

