- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个数据库查询:
var configs = dbData.Configs.Where(e => headers.Contains(e.headerId) && e.flag == "true");
if(configs.Any())
{ ... }
其中 configs 作为 IQueryable 类型返回。我有时会收到此错误:
System.InvalidOperationException: The cast to value type 'Boolean' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type. at System.Data.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader
1.GetValue(DbDataReader
1.ReadNextElement(Shaper shaper) at System.Data.Common.Internal.Materialization.Shaper
reader, Int32 ordinal) at
System.Data.Common.Internal.Materialization.Shaper.GetColumnValueWithErrorHandling[TColumn](Int32
ordinal) at
System.Data.Common.Internal.Materialization.Coordinator1.SimpleEnumerator.MoveNext()
1 source) at System.Linq.Queryable.Any[TSource](IQueryable`1 source)
at System.Linq.Enumerable.Single[TSource](IEnumerable
它发生在生产中,似乎是随机的,我无法在开发中重现它。
编辑添加:Config 类型有一个外键约束,如果 bool 类型是从中转换的,我不知道。 Entity Framework 创建的 Config 类型中没有 Boolean,Sql Server 中也没有 Boolean 类型。
最佳答案
您的 Configs 表中有一些数据库列具有可为 null 的 bool 类型,但您将表条目映射到的 C# 实体被定义为使用不可为 null 的 bool 值。当查询提供程序填充 C# 实体时,当它遇到 null
值时,它会抛出此异常。您需要更新实体对象,以便相关列的类型正确。
关于c# - Queryable.Any() 返回空值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25246178/
重现问题的代码 我遇到了一个 IQueryable.Where 的情况电话返回 IQueryable其中 TOther != TSource .我整理了一些示例代码来重现它: using System
例如,我有一个 Product 实体、一个 ProductViewModel 和一个 Label 实体。我的两个产品属性对应于标签代码而不是实际值。例如,产品的名称是“code1234”,它对应于具有
我正在使用 Diesel crate执行一些数据库工作。在某些表中,应将表的两列一起视为一个键。 这种模式在数据库中的许多地方都重复出现,因此最好避免使用大量重复的复制粘贴代码来处理这种情况。但是,我
我正在使用 EF6 为应用程序实现搜索/筛选器 UI 的后端。我有代码构建一个与 Queryable.Where 一起使用的表达式,对于给定的 DbSet,DbSet 的类型在运行时确定(DBCo
我有一个数据库查询: var configs = dbData.Configs.Where(e => headers.Contains(e.headerId) && e.flag == "true")
如何声明这样的变量? var rData = from nc in ctx.NEWSLETTER_CLIENTS join ni
1.在数据库中以json字符串格式保存,如:[{"name":"张三","time":"8.592","ar
重要 问题不是“Queryable.OfType 有什么作用,而是“我在那里看到的代码是如何实现的?” 反射(reflection) Queryable.OfType,我看到(经过一些清理):
你怎么了黑帮? 我有以下代码似乎总是返回 null。 public static T GetNext(this IQueryable list, T current) {
我有以下代码 var results = repository.GetItemsAsQuery().Where( user =>
我正在编写一个转换 IQueryable 查询的访问者。它使用带有种子 null 的 Aggregate 方法,然后使用一些 func 对其进行转换。我的问题是这个 null 是 decimal? 类
我有这个存储库方法: public IQueryable GetAll() { using (var context = new DatabaseContext()) {
我不太了解界面,所以我想我会以一种有助于我更好地理解它的方式来表述这个问题。 我正在学习如何制作 IQueryable 的教程。为什么我不能只做一个 Queryable? 最佳答案 Queryable
我对 Linq 有点陌生,希望有人能帮助我解决我目前正在苦苦挣扎的事情。 我目前有 2 个列表 public IQueryable Roles { get { var role
我有一个 ASP.NET 站点,它已经完美运行了很长时间,最近没有任何变化。从一个小时到下一个小时,我开始在我执行 LINQ 查询的一行中收到 IndexOutOfRangeException: va
我想知道如何在列表中存储 orderby 表达式。这就是我想写的: List>> list = new List>>() { p => p.Name, p => p.Id }; 然后: var
我正在构建一个基于 LINQ 的查询生成器。 其中一项功能是能够将任意服务器端投影指定为查询定义的一部分。例如: class CustomerSearch : SearchDefinition {
我正在尝试在我的 API 中实现 Guardian 并通过它执行登录以获取 JWT。我正在看的教程是here .问题是使用类似于他们在示例中使用的用户模型来实现登录。模型代码如下所示: defmodu
我有一个简单的 GET 方法,它返回 IQueryable,并且对查询有一些先决条件: [Queryable(HandleNullPropagation = HandleNullPropagation
我有一个简单的 WebApi 方法,就像这样用 OData 可查询属性装饰。 [Queryable] public virtual IQueryable Get() {
我是一名优秀的程序员,十分优秀!