内部 .NET Framework 数据提供程序错误 1025 [英] Internal .NET Framework Data Provider error 1025

查看:34
本文介绍了内部 .NET Framework 数据提供程序错误 1025的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IQueryable<Organization> query = context.Organizations;

Func<Reservation, bool> predicate = r => !r.IsDeleted;

query.Select(o => new { 
    Reservations = o.Reservations.Where(predicate)
}).ToList();

此查询引发内部 .NET Framework 数据提供程序错误 1025"异常,但下面的查询不会.

this query throws "Internal .NET Framework Data Provider error 1025" exception but the query below does not.

query.Select(o => new { 
    Reservations = o.Reservations.Where( r => !r.IsDeleted)
}).ToList();

我需要使用第一个,因为我需要检查一些 if 语句来构造正确的谓词.我知道在这种情况下我不能使用 if 语句,这就是我将委托作为参数传递的原因.

I need to use the first one because I need to check a few if statements for constructing the right predicate. I know that I can not use if statements in this circumstance that is why I pass a delegate as parameter.

如何使第一个查询起作用?

How can I make the first query work?

推荐答案

虽然上述答案是正确的,但请注意,在 select 语句之后尝试使用它时,必须显式调用 AsQueryable(),否则编译器将假定我们正在尝试使用 IEnumerable 方法,该方法需要 Func 而不是 Expression.

While the above answers are true, note that when trying to use it after a select statement one has to call AsQueryable() explicitly, otherwise the compiler will assume that we are trying to use IEnumerable methods, which expect a Func and not Expression<Func>.

这可能是原始海报的问题,否则编译器大部分时间都会抱怨它正在寻找 Expression 而不是 Func.

This was probably the issue of the original poster, as otherwise the compiler will complain most of the time that it is looking for Expression<Func> and not Func.

演示:以下将失败:

MyContext.MySet.Where(m => 
      m.SubCollection.Select(s => s.SubItem).Any(expr))
         .Load()

虽然以下将起作用:

MyContext.MySet.Where(m => 
      m.SubCollection.Select(s => s.SubItem).AsQueryable().Any(expr))
         .Load()

这篇关于内部 .NET Framework 数据提供程序错误 1025的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆