forum

Home / DeveloperSection / Forums / LINQ to SQL Efficiency

LINQ to SQL Efficiency

Anonymous User 1831 08-Dec-2014

I am new to LINQ and I have a question regarding a "Hit the database once" type of transaction. 

In the below code I am databinding the results of a query to a radio list. I want to run the query once, then work with the results before databinding. IE: If there are values, databind to the Radio list, otherwise show a textbox stating there are no values. 

From my online searches I have only found that I can run the query once with a .count(), then run it again if the .count() is > 0. 

I would prefer to hit the database once, then count the records, and proceed using the same resultset. 

I was not sure of the terminology to use when searching, so please respond with the approprate terminology to use so that I can find the answer on my own! 

using (RTOExceptionDataContext thisDataContext = new RTOExceptionDataContext())
{
    rdoSelectTransition.DataSource =    from tracking in thisDataContext.vw_RTOExceptionWorkflowTransitionMaps
                                                where tracking.RTOExceptionId.Equals(Convert.ToInt32(Request.QueryString["RTOExceptionId"])) &&
                                                tracking.RTOSecurityLevel.Equals((int)Master.thisUserSecurityLevel)
                                                select new { tracking.RTOTransitionCd, tracking.TransitionDisp };
    rdoSelectTransition.DataTextField = "TransitionDisp";
    rdoSelectTransition.DataValueField = "RTOTransitionCd";
    rdoSelectTransition.DataBind();
}


Updated on 09-Dec-2014
I am a content writter !

Can you answer this question?


Answer

2 Answers

Liked By