Question

I am using LINQ to Entities 4.1.

Enjoying using LINQPAD, however I have noticed that LINQ queries can take a long time, and this I believe is due to all the linked tables being queried as well. I only require the top level resultset which happens in my asp.net application which is quick. I have noticed this in other LINQ using tools like Devart's Entity Developer. Obviously this is very useful when you want to drill through data, but not when you do not due to slow retrieval.

Advice on how I can stop this nested retrieval happening in tools. Perhaps it is an addition to my LINQ query?

Was it helpful?

Solution

You can use the Dump(this object o, int depth) overload to control the depth of the query.

For example:

myQuery.Dump(1);

will only select things from the properties of the objects returned, but not of the properties of those properties.

If you run the following example you can see it in action:

void Main()
{
    var a = new A
    {
        B = new B
        {
            Foo = "Deep",
        },
    };

    a.Dump();  //Shows properties of all properties.
    a.Dump(1); //Does not show properties of B.
}

class A
{
    public B B { get; set; }
}

class B
{
    public String Foo { get; set; }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top