How do I check if a SQL Server 2005 TEXT column is not null or empty using LINQ To Entities?
Posted
by emzero
on Stack Overflow
See other posts from Stack Overflow
or by emzero
Published on 2010-05-05T19:44:48Z
Indexed on
2010/05/05
19:48 UTC
Read the original article
Hit count: 299
Hi there guys
I'm new to LINQ and I'm trying to check whether a TEXT column is null or empty (as String.IsNullOrEmpty).
from c in ...
...
select new
{
c.Id,
HasBio = !String.IsNullOrEmpty(c.bio)
}
Trying to use the above query produces an SqlException:
Argument data type text is invalid for argument 1 of len function.
The SQL generated is similar to the following:
CASE WHEN ( NOT (([Extent2].[bio] IS NULL) OR (( CAST(LEN([Extent2].[bio]) AS int)) = 0))) THEN cast(1 as bit) WHEN (([Extent2].[bio] IS NULL) OR (( CAST(LEN([Extent2].[bio]) AS int)) = 0)) THEN cast(0 as bit) END AS [C1]
LEN is not applicable to TEXT columns. I know DATALENGTH should be used for them...
How can I force LINQ to produce such thing? Or any other workaround to test if a text column is null or empty???
Thanks!
© Stack Overflow or respective owner