Why does this work:
result = (from e in db.CampaignCodes where e.Code.Equals('') && e.Domain.Equals(null) select e).FirstOrDefault();
But not (result is null):
String code = ''; String domain = null; result = (from e in db.CampaignCodes where e.Code.Equals(code) && e.Domain.Equals(domain) select e).FirstOrDefault();
??
That does indeed sound quite odd. LINQ to SQL may well notice the difference between getting the value from a variable and getting it from a constant, but I wouldn’t have expected it to make any difference.
I strongly recommend that whenever LINQ to SQL appears to be behaving oddly, you turn the context logging on and see what query it’s actually executing in each case.
EDIT: The other answers around the overloading aspect are really interesting. What happens if you declare the
domainvariable as typeobjectinstead ofstringin the second query, or cast thenulltostringin the first query?