Using Count() function throws “Internal .NET Framework Data Provider error 1025.”

Pra*_*dav 0 .net c# linq

This is my code:

var icdCodes = DbContext.MasterIcd.Select(x => x.IcdCode).AsQueryable();
var count = icdCodes.Where(x => !x.Any(char.IsDigit)).Count();
Run Code Online (Sandbox Code Playgroud)

I'm trying to find those IcdCodes which doesn't contain any characters. But using count throws the following error: “Internal .NET Framework Data Provider error 1025.”

As mentioned in Internal .NET Framework Data Provider error 1025 I'm using AsQuerable() but still getting the error. Please help

Cod*_*ter 6

The AsQueryable() does not solve this other cause of the same error. As also explained in Casting LINQ expression throws "Internal .NET Framework Data Provider error 1025.", the problem is that Where(x => !x.Any(char.IsDigit)) can't be translated to SQL.

The C# code you use treats a string as a char array and calls a function that uses a Unicode lookup table to check if each character is a digit.

The T-SQL variant of this is ISNUMERIC. See How to know if a field is numeric in Linq To SQL:

DbContext.MasterIcd
         .Select(x => x.IcdCode)
         .Where(i => SqlFunctions.IsNumeric(i) == 1)
         .ToList();
Run Code Online (Sandbox Code Playgroud)

  • 谨慎使用ISNUMERIC。关于什么是“数字”,包括“ $”,“-”,“。”和“ 10,3”之类的东西,都极为松懈。这相当于检查每个字符是否都是数字,但是肯定不是一回事-SqlFunctions.PatIndex(“%[^ 0-9]%”,i)== 0更近了。 (2认同)