我有一个linq查询,我想在数据库字段中包含那些非空或空的记录,但是当我使用string.isNullorEmpty时,它会给我错误.我怎样才能实现我的查询任务
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
Run Code Online (Sandbox Code Playgroud)
如果我将string.IsNullOrEmpty(pstmt.vcr_MetaValue)== false更改为pstmt.vcr_MetaValue!= string.Empty它给我SQL Server不处理NText,Text,Xml或Image数据类型的比较错误
好吧,错误信息似乎相当清楚 - 我怀疑如果你想能够做到这一点,你需要使用一个nvarchar字段而不是text/ ntext.
编辑:不只是数据库字段需要是正确的类型; 它也是LINQ to SQL认为的类型.您需要使DBML与实际的数据库架构保持同步.