gpt4 book ai didi

c# - 在 linq 查询中使用 string.IsnullorEmpty 的问题

转载 作者:行者123 更新时间:2023-11-30 13:50:39 26 4
gpt4 key购买 nike

我有一个 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

如果我将 string.IsNullOrEmpty(pstmt.vcr_MetaValue) == false 更改为 pstmt.vcr_MetaValue != string.Empty 它给我 SQL Server does not处理 NText、Text、Xml 或 Image 数据类型的比较错误

最佳答案

嗯,错误信息似乎相当清楚 - 我怀疑如果你想能够做到这一点,你需要使用 nvarchar 字段而不是 text/ntext.

编辑:不仅仅是数据库字段需要是正确的类型;它也是 LINQ to SQL 认为的类型。您需要使您的 DBML 与您的实际数据库架构保持同步。

关于c# - 在 linq 查询中使用 string.IsnullorEmpty 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5881661/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com