开发者

Strange cast error with Linq and Oracle

开发者 https://www.devze.com 2023-01-17 14:46 出处:网络
I am getting a cast error with Linq to a DataTable that was populated with Oracle. bool isTrue开发者_C百科 = DataTable.AsEnumerable().Any

I am getting a cast error with Linq to a DataTable that was populated with Oracle.

bool isTrue开发者_C百科 = DataTable.AsEnumerable().Any
      (x => x.Field<int>("MYNUMBERFIELD") == MYNUMBER);

In SQL this works fine as expected. In Oracle is fails with a cast error on the cast. In C# code the same thing happens when you do the following:

int myint = (int)VariableRetrievedFromOracleDB;

If you change it to int myint = Convert.ToInt32(VariableRetrievedFromOracleDB) it works fine.

Any ideas how to handle this with the lambda?


bool isTrue = 
    DataTable.AsEnumerable()
             .Any(x => Convert.ToInt32(x.Field("MYNUMBERFIELD")) == MYNUMBER);
0

精彩评论

暂无评论...
验证码 换一张
取 消