News, examples, tips, ideas and plans.
Thoughts around ORM, .NET and SQL databases.

Wednesday, September 09, 2009

null.MethodCall(...) issue on Memory storage

The problem: this code works differently on Memory and SQL storages.
var query =
from c in Query<Person>.All
where c.FirstName.ToLower()=="alex"
select c;
foreach (var c in query)
Console.WriteLine(c.FirstName);
The reason is pretty simple: we don't replace method calls on primitive types to their versions performing null checks while compiling the query for Memory storage. So if this code will be executed on IMDB, it has a chance to fail with NullReferenceException in FilterProvider iterator.

Currently you can workaround this issue by e.g. this code:
var query =
from c in Query<Person>.All
where (c.FirstName ?? string.Empty).ToLower()=="alex"
select c;
foreach (var c in query)
Console.WriteLine(c.FirstName);
But as you might suspect, this can affect on query plans in SQL. So better option is to make DataObjects.Net to handle this. That's exactly what we're going to implement in the near future.

1 comment: