Prashant Yadav
Prashant Yadav

Reputation: 551

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

This is my code:

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

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

Upvotes: 0

Views: 247

Answers (2)

Holger
Holger

Reputation: 2654

Not every Request is translatable into SQL. Splitting a string into an character array and doing array-options on it, might be one of them.

Approach A. You load all you strings im Memory (replacing AsQueryable with ToList()) And do your Test locally. (your code is OK).

Approach B. If your IcdCode is of limited length (maximum 9), it could be simpler, just to TryParse it to int or long, disallowing signs if you want. With this Type-Conversion approach there could be also a solution that can be expressed in SQL. (Like if conversion is possible than ...). But it sometimes hard to find out how to express something in C#, that can be converted to SQL, this is what actually is done when executing LINQ to SQL, and it still depends on the type of SQL-Server itself.

Upvotes: 0

CodeCaster
CodeCaster

Reputation: 151604

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();

Upvotes: 6

Related Questions