score:7

Accepted answer

in the sql world, by definition, any expression that has null as part of it becomes null. this is because null means an indeterminate value - an indeterminate value + anything else is still an indeterminate value, i.e. null.

again, in sql you could use something like coalesce to convert nulls into, say, a blank string - i don't recall off hand what the linq equivalent is.

score:1

with .toarray(), you are using linq against a .net type, which is evaluated in code and uses .net type handling. here, the string concatenation methods work the way you are used to.

without .toarray, your query is executed in the dbms and uses whatever that system is configured to use for null values.

in this case the dbms is configured to handle nulls according to the ansi standard, which is very different from .net in places. you should look up ansi nulls to find out the details. it isn't complicated, but can be confusing if you aren't expecting it.

two addenda 1) first, i believe the concatenation rules for nulls are laid out in the ansi standard, but actually i realize i could be wrong. i came from a sql server background, where ansi_nulls is a setting controlling null equality, whereas concatenation is controlled by another one. if i am wrongly linking the latter to the former, i apologize.

2) despite my talking about configurability, and the fact that sql server at least does allow changing that configuration, it is absolutely the case that the behavior you are seeing is standard, default, and expected. you should get used to it if you will be working with databases much at all.


Related Query

More Query from same tag