This query is 3 times slower in execution when I execute it from the code than when I execute the equivalent SQL from SQL Server Management Studio
code
var myDataContext = new AccessMyDatabaseDataContext();
myDataContext.ObjectTrackingEnabled = false;
var schedule = (from s in myDataContext.MyTable
where s.Date >= StartDate
&& s.Date <= EndDate
&& s.Name == "MySchedule"
&& (s.Status.Equals("LIVE") || s.SomeOtherField.Equals("MyString"))
select s)
.ToList();
I have a variable number of expected records, so I can't assign a direct number of expected records. I think the reason for the extra-time is that Linq2sql executes select top 1
statements as long as it finds records.
Does somebody know a way to solve this issue?
EDIT
At the End, it was more me than Linq2Sql. SORRY!
I took 3 Tables with (almost) the same syntax (above), to assign my business-object with needed values in a foreach-loop. The problem was, that one of those access-queries was without the ToList-Command. The foreach loop took to values from my List-Objects an one from my Database.
An awkward beginner-mistake. Sorry again and thanks for your help!!!