简体   繁体   English

获取数据是 Null 错误,同时尝试在 SQL 位数据类型中使用 Linq 查询获取包含错误值的记录

[英]Getting Data is Null error while trying to fetch record containing false value in SQL bit datatype using Linq query in C#

I am working in ASP.Net Web API .net 6. I have a column isAssigned having bit datatype in my SQL table. I am working in ASP.Net Web API .net 6. I have a column isAssigned having bit datatype in my SQL table. I want the records having false value in isAssigned column .我希望记录在isAssigned column中具有false value When I try fetching it using my LINQ query I get the following error:当我尝试使用我的 LINQ 查询获取它时,我收到以下错误:

System.Data.SqlTypes.SqlNullValueException: 'Data is Null. System.Data.SqlTypes.SqlNullValueException:'数据是 Null。 This method or property cannot be called on Null values.'不能对 Null 值调用此方法或属性。

This error occurs only when I try to fetch rows with false value in isAssigned column.仅当我尝试在isAssigned列中获取具有错误值的行时,才会发生此错误。

var record = _todoContext.OneTimeCodes.Where(x => x.IsAssigned == false).ToList();

Yes, I found it.是的,我找到了。 I had a date column with null value, hence got that error.我有一个带有 null 值的日期列,因此出现了该错误。 Made the date column as not null and the problem is solved.将日期列设置为不是 null,问题就解决了。 Thanks.谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#-如果查询中存在空值,则使用Linq获取数据 - C# - Using Linq get data if null value exist in query C#使用Linq到Sql获取数据 - C# fetch data using Linq to Sql 尝试使用C#更新Ms Access 2007中的记录时出现错误 - Getting Error while trying to update record in Ms Access 2007 using c# 将数据表转换为Linq查询C#时出错 - getting error while converting datatable to Linq Query C# 尝试读取 C# .net 6.0 控制台应用程序中的 ConnectionString 值时,得到 Object 参考 Z37A6259CC0C8DAEFF02 错误 - While trying to read ConnectionString value in C# .net 6.0 console app getting Object reference null error Linq查询包含空值 - Linq query containing null value 如何使用 LINQ 将 SQL 中的时间戳数据类型值转换为 C# 中的日期时间格式? - How to convert Timestamp Datatype value in SQL in Datetime format in C# by using LINQ? 如何在C#中使用LINQ查询将列表的先前记录列值与当前记录列值进行比较 - How to compare previous record column value with current record column value of a list using LINQ query in C# 在C#,SQL Server中执行查询时出错:尝试更新已存在的值,否则插入 - Error while executing query in C#, SQL Server: trying to update if value already present else insert 在C#代码中将SQL位数据类型转换为1或0 - Convert SQL bit datatype to 1 or 0 in C# code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM