0

Im using Entity Framework 6 to access an Oracle database. I have a query like the following one:

var query = db.Table
    .Where(x => x.Field1 == field1 || x.Field1 == "ConstantValue")
    .Where(x => x.Field2 == field2 || x.Field2 == "ConstantValue")
    .OrderByDescending(x => x.Field1)

When I execute it, I get the following error: ORA-01008: not all variables bound

I know what this message normally means, but it doesn't make any sense here. field1 and field2 are not null. Please can anyone help me to solve this problem?

Pinzi
  • 293
  • 6
  • 18
  • if you try the following : var query = db.Table .Where((x => x.Field1 == field1 || x.Field1 == "ConstantValue") && (x => x.Field2 == field2 || x.Field2 == "ConstantValue")) .OrderByDescending(x => x.Field1) – SomeCode.NET Jan 26 '16 at 16:44
  • In that way it is not possible, but I tried the following: db.Table.Where(x=> ((x.Field1 == field1 || x.Field1 == "Constant") && (x.Field2 == field2 || x.Field2 == "Constant"))) ... and get the same error – Pinzi Jan 26 '16 at 16:53
  • One more question, is the property Field1 or the property Field2 Nullable ? if yes, try test first HasValue : Where(x => x.Field1.HasValue && (x.Field1 == field1 || x.Field1 == "ConstantValue") ... – SomeCode.NET Jan 26 '16 at 17:08
  • No, both of them are not Nullable. When I remove the part behind || it would be working, but when I add it I always get this exception, no matter what syntax I try :( – Pinzi Jan 26 '16 at 17:48
  • I found the problem. My constant value is in a static class, and it looks like that is not possible. When I change my "Constantvalue" to a local field everything is working :) – Pinzi Jan 26 '16 at 18:41

0 Answers0