Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem using string.IsnullorEmpty in linq query

Tags:

c#

linq

I have a linq query in which i want to include those record which are not null or empty in database field but when i use string.isNullorEmpty it gives me error. How can i achieve this task my query is

from post in PostIdPostMeta1
join pstmt in postrepository.GetAllPostMetas() on post.int_PostId equals pstmt.int_PostId
where string.IsNullOrEmpty(pstmt.vcr_MetaValue) == false
select post

If i change string.IsNullOrEmpty(pstmt.vcr_MetaValue) == false to pstmt.vcr_MetaValue != string.Empty it give me SQL Server does not handle comparison of NText, Text, Xml, or Image data types error

like image 792
Fraz Sundal Avatar asked Jul 01 '26 13:07

Fraz Sundal


1 Answers

Well, the error message seems reasonably clear - I suspect that if you want to be able to do this, you'll need to use an nvarchar field instead of text / ntext.

EDIT: It's not just the database field that needs to be the right type; it's also the type that LINQ to SQL thinks it is. You need to keep your DBML in sync with your actual database schema.

like image 70
Jon Skeet Avatar answered Jul 03 '26 02:07

Jon Skeet