Hello,
I am trying to get serialized results from a WCF service from database using linq.
The tables in the db are normalized to some extent and I'm returning some other data along with the on that I initially retrieve with a linq query using Data.Linq.DataLoadOptions, just like in Scott Landford's Blog: http://codeexperiment.com/post/Returning-LINQ-to-SQL-Entities-From-WCF.aspx
Here's a part of my code that is relevant:
ServerDALDataContext db = new ServerDALDataContext();
System.Data.Linq.DataLoadOptions dlo = new System.Data.Linq.DataLoadOptions();
// get COMPETITOR_ENTRies data along with COMPETITION
dlo.LoadWith<COMPETITION>(e => e.COMPETITOR_ENTRies);
// get dividends for competitors along with COMPETITOR_ENTRies
dlo.LoadWith<COMPETITOR_ENTRY>(e => e.DIVIDENDs);
db.LoadOptions = dlo;
// retrieve MEETING data from database
var competitions = (from c in db.COMPETITIONs
select c)
.AsEnumerable()
.Where(c => c.CONTROL_UPDATE_DATA.FOR_UPDATE);
&& c.COMPETITION_DATETIME.Value.Date == dateFrom.Date);
// return as list
return competitions != null ? competitions.ToList() : null;
There is also a client application that consumes the service, sending asynchronous requests to the WCF service on every 10 seconds or so.
The problem that arrises is that when this is used, it actually overloads the SQL server to such extent that it uses 100% CPU all the time, causing the responses to the client to be late. I remove the dlo.LoadWith calls and responses come in a meaningful time.
Any suggestions on how to resolve this issue, and not overload the SQL server that much?
Thanks in advance,
Bojan