1.) I have a problem (lack of knowledge probably) on prefetching nested entities. My Entity has a reference to Entity which has EntitySet (A.B.C; A = Entity, B = Entity and C = EntitySet) I Would like to prefetch nested EntitySet (C) with all of its properties. Can you help? 2.) Can Lazzy loading be used on disconnectedState? How? Many Thanks, Sandi This thread was imported from our support forum. The original discussion may contain more detailed answer. Original topic by Zgckula. |
Alex (Xtensive) wrote:1) Prefetch works absolutely the same way with DisconnectedState. The only thing you must remember is that Connect() must be used to make direct queries. So:
Alex (Xtensive) wrote:Another alternative:
The result of this code must be identical from the point of fetched objects, but this approach is actually a bit more effecient: -A.B relationship is fetched with JOIN -B.C relationship is fetched with use of future queries. See http://blog.alexyakunin.com/2009/11/new ... ching.html First approach implies everything is fetched with future queries, but A.B relationship is fetched with ~ a set of "... WHERE ... IN (...)" queries. We use nearly the same approach is for local collections support here: Alex (Xtensive) wrote:
Denis Krjuchkov (Xtensive) wrote:Hello, Sandi.
This is a feature. Let me explain theoretical part first.
There are two ElementAt extension methods.
One for IEnumerable<t> and one for IQueryable<t>. IQueryable is a subtype for IEnumerable.
When you write something.ElementAt(0) compiler automatically chooses the best matching extension method.
Our EntitySets implement IQueryable interface, so extension method for IQueryable is called.
IQueryable is an entry point for LINQ to
However, it seems you want to use ElementAt extension method for IEnumerable rather than for IQueryable. There is a standard helper for this. Consider using AsEnumerable. It does nothing but upcast from IQueryable to IEnumerable.
ToArray works pretty well because there is no such extension method for IQueryable, so extension method for IEnumerable is used. Alex (Xtensive) wrote:Worse: b.c.ElementAt(someIndex); is actually a shortcut for:
That's just FYI ;) Zgckula wrote: Thanks! I have prefetched correctly myself for the first time but obviously i was misled by the following bug: a.b.c.ElementAt(0) wants to connect and throws exception a.b.c.ToArray()[0] works fine Regards, Sandi |