2012-03-22 97 views
0

看来,如果是空值存储在一个变量实体框架是不能对空比较值: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的SQL Server Compact 4.0与实体框架条件字符串比较

所以我做这样的事情正如其他SO用户所建议的那样:

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

虽然这种技术在处理int时工作得很好吗?或double?时,SQL Server Compact在使用字符串时会抛出EntityCommandExecutionException(如上例所示)。例外包含以下细节:

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 

任何想法,为什么我得到这个以及我如何克服它?

回答

1

是的,显然是ISNULL is funky in Compact

你可以做在客户端上,但:

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

...我怀疑没有ISNULL会在这种情况下产生的。