locked
Count Records in Linq RRS feed

  • Question

  • User-2048571045 posted

    I want to get a count of complexQuery:

    string refName = entity.GetAttributeValue<string>("contractorname");
     
       var complexQuery = (from c in orgContext.CreateQuery<contractorframe>()
                           join e in orgContext.CreateQuery<dcc_eval>()
                            on c.ContractorName equals e.RegardingObjectId.ToString()
                            where e.RegardingObjectId.ToString() == refName 
                            and e.QW Is Not Null)
    

    Anyone know how to get count of complexQuery above in Linq?

    Thursday, October 15, 2015 11:28 AM

Answers

  • User753101303 posted

    .Count(); as C# is case sensitive. What happens when trying that?

    Here it would be if you are just interested in the count. Else you could keep the query handy and call its Count() method as needed or also you could retrieve all the data client side and do the count client side (a bit more work client side but one query rather than two on the database side).

    If it doesn't work be explicit about what happens so that we can give it a try knowing what is the issue you have.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 15, 2015 12:52 PM
  • User-271186128 posted

    Hi macca,

    As PatriceSc said, I suggest you could refer to the following code:

       string refName = entity.GetAttributeValue<string>("contractorname");
    //Get the filter records var complexQuery = from c in orgContext.CreateQuery<contractorframe>() join e in orgContext.CreateQuery<dcc_eval>() on c.ContractorName equals e.RegardingObjectId.ToString() where e.RegardingObjectId.ToString() == refName and e.QW Is Not Null; //Get the count int count = complexQuery.Count(); //Besides, you could also try to use the following code to get the count. int count2 = complexQuery.ToList().Count;

    Best regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 15, 2015 10:19 PM

All replies

  • User753101303 posted

    Hi,

    You should see a Count() extension method:

    var rowCount=complexQuery.Count();

    If it doesn't work what happens? Or this is not what you meant?

     

    Thursday, October 15, 2015 11:42 AM
  • User-2048571045 posted

    How would I apply that to the above code?

    What would it look like?

    Like this ?

    string refName = entity.GetAttributeValue<string>("contractorname");
     
       var complexQuery = (from c in orgContext.CreateQuery<contractorframe>()
                           join e in orgContext.CreateQuery<dcc_eval>()
                            on c.ContractorName equals e.RegardingObjectId.ToString()
                            where e.RegardingObjectId.ToString() == refName 
                            and e.QW Is Not Null).count()

    Thursday, October 15, 2015 12:01 PM
  • User753101303 posted

    .Count(); as C# is case sensitive. What happens when trying that?

    Here it would be if you are just interested in the count. Else you could keep the query handy and call its Count() method as needed or also you could retrieve all the data client side and do the count client side (a bit more work client side but one query rather than two on the database side).

    If it doesn't work be explicit about what happens so that we can give it a try knowing what is the issue you have.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 15, 2015 12:52 PM
  • User-271186128 posted

    Hi macca,

    As PatriceSc said, I suggest you could refer to the following code:

       string refName = entity.GetAttributeValue<string>("contractorname");
    //Get the filter records var complexQuery = from c in orgContext.CreateQuery<contractorframe>() join e in orgContext.CreateQuery<dcc_eval>() on c.ContractorName equals e.RegardingObjectId.ToString() where e.RegardingObjectId.ToString() == refName and e.QW Is Not Null; //Get the count int count = complexQuery.Count(); //Besides, you could also try to use the following code to get the count. int count2 = complexQuery.ToList().Count;

    Best regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 15, 2015 10:19 PM