c# - Linq to Sql escape WHERE clause -
i have linq-to-sql query
daynamiccontext.log = new system.io.streamwriter("f:\\linq-to-sql.txt") { autoflush = true }) var tt = daynamiccontext.gettable(tbl); var query = ((from c in tt c.isdeleted != true select c.id).take(1)).tolist();
the result of final query correct got single id.
the problem when have big data got out of memory exception.
when checked generated query
select [t0].[id], [t0].[createdby], [t0].[createddate], [t0].[modifiedby], [t0].[modifieddate], [t0].[isdeleted], [t0].[untiletime], [t0].[desktop], [t0].[laptop], [t0].[title], [t0].[responsive], [t0].[mobile], [t0].[activetime], [t0].[tablet] [countent_freearea] [t0]
it seems linq-to-sql getting data database , filtering on memory.
public class context { private datacontext daynamiccontext; public datacontext daynamiccontext { { if (daynamiccontext == null) { system.configuration.connectionstringsettingscollection connectionstrings = webconfigurationmanager.connectionstrings; daynamiccontext = new datacontext(connectionstrings["connectionstrings"].tostring()); } return daynamiccontext; } } }
the gettable method fetch whole table first , select first value list. instead of using take()
, use firstordefault()
.
Comments
Post a Comment