0

It seems that Entity Framework is not able to compare a value against null if that null value is stored in a variable: http://data.uservoice.com/forums/72025-ado-net-entity-framework-ef-feature-suggestions/suggestions/1015361-incorrect-handling-of-null-variables-in-where-cl?ref=title

So I'm doing something like this as suggested by other users of SO:

string description = null;
var transactions = from t in entities.Transactions
                   where description == null ? t.Description == null : t.Description == description
                   select t;

While this technique works perfectly fine when dealing with int? or double?, SQL Server Compact throws an EntityCommandExecutionException when using strings (as in the example above). The exception contains the following details:

  InnerException: System.Data.SqlServerCe.SqlCeException
       Message=The specified argument value for the function is not valid. [ Argument # = 1,Name of function(if known) = isnull ]
       Source=SQL Server Compact ADO.NET Data Provider

Any idea why I'm getting this and how I can overcome it?

Johnny Oshika
  • 54,741
  • 40
  • 181
  • 275

1 Answers1

1

Yeah, apparently ISNULL is funky in Compact.

You could do it on the client, though:

var transactions = description == null ?
                    entities.Transactions.Where(t.Description == null)
                    : entities.Transactions.Where(t.Description == description);

...and I suspect no ISNULL will be generated in this case.

Community
  • 1
  • 1
Craig Stuntz
  • 125,891
  • 12
  • 252
  • 273