Hi,

Evaluating DO I tried to play with the future queries to reduce the number of round-trips to the database, but got an exception in a very simple scenario.

This is an example that reproduces the problem.

static void Test()
{
    var config = DomainConfiguration.Load("Default");
    var domain = Domain.Build(config);

    using (var session = domain.OpenSession())
    {
        using (var transactionScope = session.OpenTransaction())
        {
            Key key = Key.Create<Item>(domain, 1);
            var item = session.Query.ExecuteDelayed(x => x.Single<Item>(key));
        }
    }            
}

The problem though can be solved by the following code (which just doesn't look as straightforward as the example above):

var item = session.Query.ExecuteDelayed(x => x.All<Item>().Single(i => i.Key == key));

asked Jan 28 '12 at 17:23

Anton's gravatar image

Anton
9335


One Answer:

Hello Anton,

This is not supported by design. Session.Query.Single() is a method to lookup session cache. It checks if entity is available in session cache and either returns existing entity or fetches entity from database with internal query (that query is not LINQ-based at all).

If you want to fetch many entities with single call consider using Session.Query.Many() method. It will both optimize round-trips to server and avoid loading entities that are already loaded.

However, it is weird that NullReferenceException is thrown instead of NotSupportedException. I'll create a bug record for that.

answered Jan 28 '12 at 22:26

Denis%20Krjuchkov's gravatar image

Denis Krjuchkov
179325

edited Jan 29 '12 at 01:19

Thanks for the clear explanation!

As for your suggestion to use Session.Query.Many(), our scenario requires loading of many objects of different type (10-15 objects), so we can't use that method.

(Jan 29 '12 at 16:46) Anton Anton's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×5

Asked: Jan 28 '12 at 17:23

Seen: 2,195 times

Last updated: Jan 29 '12 at 16:46

powered by OSQA