I'm trying to use the code below to find all contracts that are sold by a given dealer:
public List<ContractEntity> SearchForContracts()
{
List<object> foundItems = new List<object>();
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
LinqMetaData metaData = new LinqMetaData(adapter);
var q = (from cm in metaData.Contract
select cm)
.WithPath(p => p.Prefetch(cm => cm.Dealer))
.WithPath(p => p.Prefetch(cm => cm.Customer));
q = q.Where(all => all.Dealer.AccountId == 746695112);
foreach (object c in q)
{
foundItems.Add(c); // Never gets here...
}
}
return null;
}
The SQL this code generates works perfectly (I captured in Profiler and re-executed), but my foreach() is never entered.
If I use a column from the Customer table in a Where, it works (e.g. q.Where(all => all.Customer.CustomerNumber = 123)).
Does anyone know why querying a property of a related entity would fail to return values to code, even when the SQL returns records?
EDIT
After playing with .Take(), I found that things are timing out.
Taking 20 works, but taking 25 does not.
Looking at profiler, the SELECT that's taking 25 is executing in .390 seconds.
Any idea why I'm getting a timeout?
EDIT 2
A second query for a predicate was the problem. I was forcing a query on a non-indexed field in a huge table.
Everything is working as expected.