Domanda

I have been using LINQ to SQL for years now, but this is the first time I have seen this behavior.

I have a DB table with a few columns (varchar(15)) that may contain empty strings (''). I verify this by running LEN(Column) and checking the result be 0.

Now when I call this from LINQ2SQL, it returns the object field with a string containing a single space (string.Length == 1).

There are a few workarounds I could apply, like making them NULL on the DB or trimming the string, but I would like to know if anyone has come across this before or if the bug is known (reported on MS Connect). If not, I'll report it.

Thanks.

È stato utile?

Soluzione

The issue is with the LEN function:

SELECT LEN(' ')

Returns 0 in SQL Server; it is a total PITA.

But

SELECT DATALENGTH(' ')

Returns 1

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top