如何解决"内部的.NET Framework数据提供程序错误1025"? [英] How to get around "Internal .NET Framework Data Provider error 1025."?

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

问题描述

我是4.3,POCO,数据库首先使用实体​​框架,我收到以下错误:

I am using the Entity Framework 4.3, POCO, database first and I am getting the following error:

内部的.NET Framework数据提供程序错误1025。

问:我认为我的查询EX presses我的意图,但我似乎打这个错误,所以我想知道,如果有人知道我怎么能组织我的查询不同,以解决这个错误? / EM>

QUESTION: I think that my query expresses my intent but I seem to be hitting this error, so I am wondering if anyone knows how I could structure my query differently to get around this error?

下面是该方案...

我有一个SQL Server 2008数据库,有2表 - A和B:

I have a SQL server 2008 database that has 2 tables - A and B:

A

  • 援助(INT - 不为空 - 标识 - 主键)
  • AName(为nvarchar(10) - 不为null)

B

  • 投标(INT - 不为空 - 标识 - 主键)
  • SomeName(为nvarchar(10) - 不为null)
  • 援助(INT - 不为空 - 外键连接表中A到AID)

然后我定义像这样的背景下:

I then define the context like so:

public class DatabaseContext : DbContext
{
    public DatabaseContext(string name)
        : base(name)
    {
        Configuration.AutoDetectChangesEnabled = false;
        As = Set<A>();
        Bs = Set<B>();
    }

    public DbSet<A> As { get; private set; }
    public DbSet<B> Bs { get; private set; }
}

而像这样的实体类:

And the entity classes like so:

public class A
{
    public int AId { get; set; }
    public string AName { get; set; }
    public virtual ICollection<B> Bs { get; private set; }

    public void AddB(B b)
    {
        if (b == null)
        {
            throw new ArgumentNullException("b");
        }

        if (Bs == null)
        {
            Bs = new List<B>();
        }

        if (!Bs.Contains(b))
        {
            Bs.Add(b);
        }

        b.A = this;
    }
}

public class B
{
    public int BId { get; set; }
    public A A { get; set; }
    public string SomeName { get; set; }
}

现在的查询......

Now for the query...

我要的是所有的作为,每一个B SomeName是提供这样的名称列表我这样做:

What I want is all of the As where every "B SomeName" is in the list of names supplied so I do this:

var names = new[] {"Name1", "Name2"};

var ctx = new DatabaseContext("EFPlayingEntities");
var res = ctx.As.Where(a => a.Bs.Select(b => b.SomeName).All(names.Contains));

// Here I evaluate the query and I get:
//   Internal .NET Framework Data Provider error 1025.
Console.WriteLine(res.Count());

要清楚明白我的意思,如果表中的数据是这样的:

To be clear about what I mean, if the table data looks like this:

AId,AName
1,A1
2,A2
3,A3
4,A4

BId,SomeName,AId
1,Name1,1
2,Name2,1
3,Name1,2
4,Name1,3
5,Name3,3
6,Name1,4
7,Name2,4

我希望找回A1,A2和A4(这样算调用上面将返回3)。

I would expect to get back A1, A2 and A4 (so that count call above would return 3).

推荐答案

之所以出现这种情况是很微妙的。

The reason why this happens is subtle.

Queryable.All 需要被调用与防爆pression 。传递在刚刚方法参考创建一个委托,随后, Enumerable.All 成为候选人,而不是预期的 Queryable.All

Queryable.All need to be called with an Expression. Passing in just the method 'reference' creates a delegate, and subsequently, Enumerable.All becomes the candidate instead of the intended Queryable.All.

这就是为什么你的解决方案,您张贴作为一个答案可以正常工作。

This is why your solution you posted as an answer works correctly.

修改

因此​​,如果你写的声明,因为这,它会工作无一例外:

so if you write the statement as this, it will work without exception:

var res = ctx.As.Where(
  a => a.Bs.Select(b => b.SomeName).All(b => names.Contains(b)));

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

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