Friday, January 6, 2012

LinqSpec null checking

Quiz: What in the following LinqSpecs spec will cause an NHibernate error if left null?

return new AdHocSpecification(o => o.ExternalAccount != null && accessMap.IdsOfManagedAccounts.Contains(o.ExternalAccount.Id));

 
 

Answer: accessMap.IdsOfManagedAccounts ...it's not o.ExternalAccount as the null check takes care of the pitfall that would otherwise be if the second half of the spec alone was the whole of the spec.

No comments:

Post a Comment