Click here to Skip to main content
15,877,857 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all i am trying to Query from a table (_dtlayout) using the LINQ to SQL. I am trying to select a column name FK_DataPoint.
But when i Debug it out it is hitting that column numerous times. It does not throw any ERROR but for Performance wise it is a major issue. I know i am using a Where clause which goes to each rows and filters it. But is there a better way to put this code together in order to filter this DATAPOINT Column. Thank you .

int? dataPointKey = _dtLayout.AsEnumerable().
    Where(row => row.Field<int?>("FK_FinancialStatementTemplateSectionItem") 
== colDef.FK_FinancialStatementTemplateSectionItem 
&& row.Field<int?>("RowNumber") == columnItem.RowNumber
&& row.Field<int?>("ColumnNumber") == colDef.ColumnNumber
&& row.Field<int?>("ItemNumber") == columnItem.ItemNumber)                                
.Select (row =>row.Field<int?>("FK_DataPoint")).FirstOrDefault();

Updated 7-Aug-14 15:57pm

1 solution

You are using a single query. U r using f11 key and so it is hitting many times if u use f10 it'll execute with in a fraction of seconds.So there will be no bigger performance issue.
Share this answer
Strikerzz Arut 12-Aug-14 3:37am    
FirstorDefault will be returning a single value.I think you will be calling this functionality indefinite times or else u'll be looping around it several times.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900