How to get around “Internal .NET Framework Data Provider error 1025.”?

后端 未结 3 1092
轮回少年
轮回少年 2021-01-06 01:11

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

Internal .NET Framework Data Provider error 1025.

相关标签:
3条回答
  • 2021-01-06 01:13

    The reason why this happens is subtle.

    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.

    EDIT

    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)));
    
    0 讨论(0)
  • 2021-01-06 01:16

    The semantics of your query look good to me; clearly, getting an internal provider error is not the intended behaviour! I would have expected some more explicit mesage about EF not being able to translate your query into a store operation, if that's in fact what the problem is.

    Another way to do what you want would be:

    var names = new[] {"Name1", "Name2"};
    var nameCount = names.Length;
    
    var ctx = new DatabaseContext("EFPlayingEntities");
    var result = ctx.As
        .Where(a => a.Bs
                     .Select(b => b.SomeName)
                     .Intersect(names)
                     .Count() == a.Bs.Count());
    

    (get every A such that intersecting its Bs' names with the fixed list gives all the Bs)

    although I haven't tried this to see if EF can translate this successfully.

    Another way:

    var names = new[] {"Name1", "Name2"};
    
    var ctx = new DatabaseContext("EFPlayingEntities");
    var result = ctx.As
        .Where(a => !a.Bs.Select(b => b.SomeName).Except(names).Any());
    

    (get every A such that the list of its Bs' names is reduced to nothing by taking out the fixed list)

    also untried.

    0 讨论(0)
  • 2021-01-06 01:17

    I have worked out a solution to this, in case anyone is interested. Doing the following is equivalent and does not result in the exception in the question:

    var res = ctx
        .Bs
        .GroupBy(b => b.A)
        .Where(g => g.All(b => names.Contains(b.SomeName)))
        .Select(g => g.Key);
    

    I do not know if this is the best way though!?

    0 讨论(0)
提交回复
热议问题