I have a class structure in entity, the looks something like this:
public class Parent
{
public int Id { get; set; }
public List<Child> Children { get; set; }
//Lots more fields....
}
public class Child
{
public int Id { get; set; }
public int ParentId { get; set; }
[ForeignKey("ParentId")]
public Parent Parent { get; set; }
//Lots more fields....
}
I then run the query on these tables using the following code:
Context.Database.Log = s => Debug.Print(s);
var ALL = Stopwatch.StartNew();
var query = context.Parent.Include(x => x.Children).Where(x => //Whatever...).ToList()();
ALL.Stop();
Context.Database.Log = null;
The output from the query debug tells me the query too 773ms eg less than a second, but the timer tells me the whole process took 2 seconds.
Given this , I assume the extra second or so is the time it takes Entity to map the data into the object - can anyone confirm if this is correct?
And more importantly - my question is, what are my options for cutting this time down?
As a note, this code:
Context.Database.Log = s => Debug.Print(s);
will output the actual SQL that is executed to a command window in visual studio.