loresoft/EntityFramework.Extended — pull request #65 by PhillP (2013-07-05 04:59:05+00:00)
Title: SqlServerBatchRunner handling of null parameters

This pull request contains a small change to address an issue I encountered with the SqlServerBatchRunner when dealing with string parameters in expressions. Where a string parameter in the expression has a null value, the SqlServerBatchRunner currently adds Parameters to the ADO.Net Command objects with null values rather than DbNull.Value which causes an exception to be thrown in some cases.

[I have recreated this pull request as the previous one was accidentally created from the wrong branch]

The type of query expression that triggered this problem is of the type:

db.Users.Where(u => u.EmailAddress.EndsWith(emailDomain) && (string.IsNullOrEmpty(optionalComparisonString) || u.AvatarType == optionalComparisonString))
.Delete();

The query can alternatively be rewritten in pieces to avoid this problem... (ie add the filter expression only where the optional parameter is non-null).. however when there are a number of these kinds of parameters it is more convenient to use the form above.

I have added some tests to cover this.