I have a simple LINQ query running on top of Entity Framework (v1) and pointing at SQL Server Compact v3.5 SP2 (8085):
var myResults = (from m in myContext.MyData
join o in myContext.SomeOtherData on new { m.ID, Name = myNameVariable } equals new { o.ID, o.Name }
select m).ToArray();
The above query will fail with the following error:
The specified argument value for the function is not valid. [ Argument # = 1,Name of function(if known) = isnull ]
If I change the query by simply replacing the myNameVariable with a hard-coded string, it works. For instance:
var myResults = (from m in myContext.MyData
join o in myContext.SomeOtherData on new { m.ID, Name = "SomeNameValue"} equals new { 开发者_如何学编程o.ID, o.Name }
select m).ToArray();
What is going on here? I am 100% positive that myNameVariable is set to a valid string. It is definitely not null.
The EF generates different SQL for these queries.
For the hard-coded string, it uses a string literal in SQL.
For the variable, it uses a SQL parameter, to defend against SQL injection (no risk with the hard-coded string, unless you do it to yourself!).
So SQL CE must be treating these two differently.
精彩评论