Hi
Since the announcement of Silverlight support by db4o (read more here, here and here) we have been asked about whether LINQ was supported also or not. Unfortunately, until a couple of weeks ago, the answer was a disappointing no;this happened mainly because db4o LINQ implementation relies on some third party libraries that did not support Silverlight.
Today we are proud to announce that the developer behind these libraries released compatible versions for Silverlight so we took the time and now you can run LINQ queries against db4o on Silverlight (note that
even though we've decided to postpone this announcement, to make sure we'd be able to test it properly, actual support was in place since 8.0 release so, the good news is that you already have production quality LINQ support)!
As you know such announcement cannot come without some sort of sample, so you can click here to see a live sample and here to download the source code. Keep in mind that the sample code is just for demostration purposes; you should ot use it as is since it has no error handling at all.
Another improvement introduced recently was the support for Skip() operator.
On db4o versions < 8.1.15588, contrary to what one would expect, the following code
var result = (from Person p in db
where p.Age > 15
select p).Skip(100);
foreach(var p in result)
{
Console.WriteLine(p);
}
will not avoid touching the first 100 objects. This happens because the previous Linq expression is translated (by the C# compiler) to something like:
var result = Enumerable.Skip(
Where(
db.Cast(),
p => p.Age > 15
),
100);
100);
foreach(var p in result)
{
Console.WriteLine(p);
}
Enumerable.Skip() is not aware of db4o activation so it will just consume (and ignore) the first 100 objects returned from db4o before it start producing results.
This poses an, unnecessary, performance penalty in scenarios where the result is paged (a common pattern in todays software) we decided to implement the Skip() operator so it will not activate the skipped objects. If you run the same query on db4o >= 8.1.15588 the compiled code will looks something like:
var result = Db4oLinqQueryExtensions.Skip(
Where(
db.Cast(),
p => p.Age > 15
),
100);
foreach(var p in result)
{
Console.WriteLine(p);
}
Noticed the difference? Now Skip() method is taken from Db4oLinqQueryExtensions (instead of Enumerable) which is aware of db4o activation mechanics so it will avoid activating any skipped objects. The best part is that no configuration is required so if you have code that uses the skip operator all you need to do is recompile using the newer db4o version.
What do you think?
Best
Your db4o team!