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

查看:380
本文介绍了内部.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 而不是表达< Func>

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>.

这可能是原始海报的问题,否则编译器会抱怨大部分时间是寻找表达式< Func> 而不是 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.

演示:
以下将失败:

Demo: The following will fail:

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

虽然以下功能将会起作用:

While the following will work:

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

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

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