c# - LINQ query returns way more results than in the entire database -


I have the following LINQ query: The problem is that 13k results are coming back when tblSurveys only 20 are all what I am doing wrong

  from centrally located in surveyContext.tblSurveys (s.Survey_Date surveyContext.tblSurvey_Types in the surveyContext.tblTypes_for_Surveys in R & gt;? = STARTDATE & amp; & Amp; s.Survey_Date & lt; = stopDate) & amp; Amp; (S.Unsubstantiated || (st.SurveyID == s.SurveyID & amp; amp; st.SurveyTypeID == t.SurveyTypeID & amp; amp; amp; amp; amp; t.UnsubstantiatedAvailable & amp; From where d.SurveyID = = S..ServveyID selection d.DeficiencyID) .ount () == 0)) by order order s.Survey_Date s;  

Do you have foreign keys and relationships setup in your database? If so, you can make your query very simple. I also recommend not changing the name of your table in the .dbml file, even if they are not all 'tbl' prefix.

You set up relationships, your query (something) can look like this.

  where (s.Survey_Date> = STARTDATE & amp; s.Survey_Date & lt; = stopDate) & amp; & Amp; (S.Unsubstantiated || (s.tblTypes_for_Surveys.Any (cents = & gt; st.tblSurvey_Type.UnsubstantiatedAvailable) & amp; amp; s.tblDeficiencies.Count () == 0)) Select Orderby s.Survey_Date ;  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -