As mentioned in the title. Is there any difference between the following two queries?
1. Entity.List.Length
2. Entity.List.Current.Count
Hi Stephen,
Consider a query GetUsers that fetches all records of Users that have their Is_Active attribute set to True.
When you access one of these two outputs of a query you will execute a query to the database, if you use the value of both, then two queries will execute: one to get the count, the other to get the requested records.
The answer to your question is "it depends":
Stephen Li wrote:
Hi,
Do you want to ask difference between Entity.List.Length and Entity.Count?
Well, when you have such queries you can assign this values to a variable and check.
Thanks
If you are using pagination, generally the query is limited by the number of records you want to show on each screen.
If the number of records you want to show on the screen is 10, your length will be a maximum of 10. Let's assume that the query found 100 records that match the filters. In this case your count will be 100. In this first case the count and the length are different.
If the number of records in the table, respecting the filters, is 10, and the number of records per page is 10, then count and length are the same.
If you are using aggregate, the length is limited by the Max Record, and the count will only look at the filters.
Hi Community,
Founded this question & comments on it very useful.
Adding little more detail to this thread as I was getting <List>.Count returned with (Not evaluated) value. <List>.Length or <List>.Count generated from an aggregate only gets value if it's been used further.
For e.g. <List>.Length generated from an aggregate will have a value if its been further used by some action ListAppendAll or other. Similarly, <List>.Count will have value if its been used in expression on Web Screen or other.
This is due to optimization done by OutSystem. Helpful article to understand query optimization - https://success.outsystems.com/documentation/11/monitoring_and_troubleshooting_apps/manage_technical_debt/code_analysis_patterns/appropriate_record_counting/
How it works can be referred to Solution - https://www.outsystems.com/forums/discussion/43057/difference-between-current-count-and-length/#Post155333
Note: Above was tested in Tradition Web Application with debugger.