C# 具有实体框架条件字符串比较的SQL Server Compact 4.0
如果null值存储在变量中,实体框架似乎无法将该值与null进行比较: 因此,我正在做一些类似的事情,正如So的其他用户所建议的那样:C# 具有实体框架条件字符串比较的SQL Server Compact 4.0,c#,entity-framework,sql-server-ce,C#,Entity Framework,Sql Server Ce,如果null值存储在变量中,实体框架似乎无法将该值与null进行比较: 因此,我正在做一些类似的事情,正如So的其他用户所建议的那样: string description = null; var transactions = from t in entities.Transactions where description == null ? t.Description == null : t.Description == description
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
你知道我为什么会这样,以及我如何克服它吗?是的,显然
不过,您可以在客户端执行此操作:
var transactions = description == null ?
entities.Transactions.Where(t.Description == null)
: entities.Transactions.Where(t.Description == description);
…我怀疑在这种情况下不会生成任何ISNULL