join rewardsmaster rm on rl. Product_Id = Products. NULLs are considered equivalent for grouping purposes. A GROUP BY clause can contain two or more columns—or, in other words, a grouping can consist of two or more columns. LATEST BLOGS Get Client IP Address In ASP. The grouping is based on a key or a composite key consisting of multiple keys. Select new. Quantity) as OrderQuantity from OrderLines inner join Products on OrderLines. Linq namespace. Linq namespace, you can apply grouping to many collections. It is good practice to always use the ORDER BY clause with the DISTINCT ON(expression) to make the result set obvious. I have a collection of huge records (6000+) wherein the object in the collections has got 50+ properties, so ideally it is not a good idea to run a "For-Each" loop here. The dt variable represents the table you wish to sort. Group by multiple expressions if you like. C# LINQ: Combine Multiple Sequences In Parallel In this article, we will see how to join multiple arrays, lists or collections by order with LINQ. NET Forums / Data Access / ADO. LINQ with lambda - How do I orderby after groupby? What I WANT to do is also order the clients (the group) by milestone date ascending so that the Client with the. I want to aggregate multiple columns from an entire source table, without using a group by. Code is more concise and readable, especially when using multiple filters. RewardType,sum(rl. Of course unambiguous names can be specified to avoid. A simple one, but I did spend some time on how to do it with Lambda Expression in How to order by multiple columns. xlsx: Column A - RSR Stock Number/Manufacturer Part Number/UPC, Column B - Order Quantity. 2016-09-22 左连接 linq to sql 分组求和怎么写; 2015-05-20 linq 中如何group by sum怎么写? 2015-05-16 linq 中group by怎么用 4; 2011-09-01 linq group by 多表连接sum等操作; 2016-11-04 linq 左连接和右连接的写法有什么区别; 2012-02-27 Linq 多表多字段group by 3; 2013-06-04 linq group by 和 order by 问题. List in descending order of orders placed customers that have placed more than 5 orders SELECT customer_id, customer_name, COUNT(order_id) as total FROM customers INNER JOIN orders ON customers. A query expression can create a new data structure. I am using Lightspeed v4. Group by and sum query on multiple. It begins with basic single-column examples before illustrating how to use LINQ group by multiple columns. After the OrderBy, add as many sorts as needed using the ThenBy function. Language Features That Support LINQ Anonymous Types Anonymous types provide a convenient way to temporarily group a set of properties into an element that you want to include in a query result. 2, Group 2 with 0. It helps learning LINQ and convert existing SQL statements. SupplierID } into g select new{ g. The SQL AGGREGATE function can be used to get summary information for every group and these are applied to an individual group. NameLinq - var result = from Orders in Context. Each player belongs to a team and have a score. This removes all duplicate elements in a collection. Using LINQ to group by multiple properties and sum. The System. Or at least all the data in the columns shown in the Order entity above. public partial classLINQ: System. The order of rows returned from the SELECT statement is unpredictable therefore the “first” row of each group of the duplicate is also unpredictable. Click the column's header to sort data against a given data column or change the column's sort order. Query result set: Practice #2: Retrieve distinct rows for the combination of two columns. com/playlist?list. first_name, d. Q: I'am trying to use a CASE expression in an ORDER BY clause to return a result set in different sort orders based on a parameter passed to the procedure. Set the SettingsBehavior. The SQL GROUP BY clause can be used in a SELECT statement to collect data across multiple records and group the results by one or more columns. In that model, a table is a set of tuples, while in SQL, tables and query results are lists of rows: the same row may occur multiple times, and the order of rows can be employed in queries (e. Categories on product. This SELECT example joins two tables to gives us a result set that displays the order_id from the orders table and the last_name from the customers table. Multiple Grouping Columns - What if I wanted to display their lastname too?. You can sort by one column in ascending order and another column in descending order. To sort descending, use the Descending keyword. MULTIPLE-TABLE SELECT. ORDER BY is the SQL command used to sort rows as they are returned from a SELECT query. 04 [Linq] 기초통계량 구하기 (0) 2015. 4 September 2014. LINQ Order By Examples in C# The order by clause in LINQ is easy to learn due to its close resemblance to the T-SQL syntax. customer_id = orders. I have taken the example of one Department containing multiple Employees. In Chapter 1, we devoted quite a bit of attention to single-table SELECT statements, concentrating primarily on the output column list and the WHERE, GROUP BY, ORDER BY, HAVING, and LIMIT clauses. UPDATED: added a new column combining the Date and Time column which are string fields into DateTimeCombined column which is a DateTime field. ORDER BY [column/columns] Aggregate Functions. Order of Entities. Using LINQ to group by multiple properties and sum. SelectMany: Probably The Most Powerful LINQ Operator it might be the case you’re constructing a query that can only execute by reaching out to the server multiple times, e. Lets take a scenario when you fill out an online form. City into StudentGroup orderby StudentGroup. This way you can select and range of values to group and give the impression in your requirement example. Lets have players. Key, g }; 语句描述:Linq使用Group By按CategoryID和SupplierID将产品分组。 说明:既按产品的分类,又按供应商分类。在by后面,new出来一个匿名类。. How do I group data using multiple columns Need of SQL Procedure for update,delete dynamic Columns and rows and Bind to asp. mysql 中order by 与group by的顺序. Tweet This Great article by @BenNadel - Getting One Record Per Group From A One-to-Many Join Woot woot — you rock the party that rocks the body!. The requirement is to concatenate…. 4 September 2014. This article presents a small utility class to sort an "IEnumerable" of objects on multiple fields by the field names provided at the run time using Linq. It seems pretty basic, but the only way options I seem to have are aggregating a single column (Orders. SQL order by command may be added to the end of any select query and it requires at least one table column to be specified in order for SQL to sort the results. 多列(Multiple Columns) var categories = from p in db. A 'recipe' is really just a collection of other products that we sell, grouped under a common h. Chart 질문에 답변을 했었는데 질문하셨던분이 아래와 같은 쿼리에 힌트를 주셔서 아싸! 레어템 전에 LINQ에 그룹바이 조건에 여러개를 어떻게 넣나 고민하다가 많이 안쓰는 관계로 미뤘었고, Chart 구현. The result from a LINQ Join differs than those generated by a nested query, the GroupBy operator, and by group joins. For every order, And for cases where you do need all the selected columns in the GROUP BY, is. Let us first write the program. Later, we have also created another group by dividing them by their age and you can see that we have 3 groups for different age groups, 21, 23 and 31. It helps learning LINQ and convert existing SQL statements. Linq Group By - Finding Duplicates This post is a little snippet on using Linq to find duplicates in a list of objects where a specific property of th. In this post, I’m going to look at a couple options from a syntax perspective that you can use to make working with outer joins easier with LINQ. Intersect(query. The grouping is based on a key or a composite key consisting of multiple keys. Results set contains three items since three distinct values existed in first column in the original set. orderData option to specify a multiple column order by default (for example [ 0, 1 ]). I have two tables with a foreign key constraint how can I delete rows from both of them in one transaction? linq to SQL seems to call my deletes in the wrong order. a2 is the table in the subquery. com Learn how to use LINQ to group by multiple columns. Performance Surprises and Assumptions : GROUP BY vs. Although DataTables doesn't have row grouping built-in (picking one of the many methods available would overly limit the DataTables core), it is most certainly possible to give the look and feel of row grouping. aapl_historical_stock_price GROUP BY year, month ORDER BY month, year Using GROUP BY with LIMIT. Below is a sample code snippet that demonstrates how to How to Implement Multiple order by in LINQ using C# […]. But, if the column I want is not even present, a default value should be used instead. The first OrderBy function of the list is the main sort. The dt variable represents the table you wish to sort. If a grouping column contains a null, that row becomes a group in the result. Detail sections contain TabPanel widgets with two tabs: Orders and Address. The SQL ORDER BY clause is used to sort the data in ascending or descending order, based on one or more columns. To sort data against multiple columns, click column headers while holding the SHIFT key. Sort by multiple fields with LINQ October 7, 2010. How to use LINQ to select an object with order by and group by { c. Showing how to exploit Group/By/Into is the point of this column. In each group, no two rows have the same value for the grouping column or columns. function() The comparator function used to determine the relative order of value pairs. Tweet This Great article by @BenNadel - Getting One Record Per Group From A One-to-Many Join Woot woot — you rock the party that rocks the body!. The following example shows how to create nested groups in a LINQ query expression. LINQ union with group by November 01, 2011 In my recent development activity with LINQ query, I need to get the some of user points from tow different tables where user's points are based on some activities. LINQ Operations. NET Forums / Data Access / ADO. Order by with dynamic columns in LINQ c# September 14, 2016 Hi Guys, sometimes we need to sort the data dynamically with dynamic column, suppose we are sowing data in grid and after click on column data should be sort, on first click it should be descending and on again click it should be ascending etc. LINQ JOIN Operator. Can some how i can use LINQ group by on multiple column without declaring anonymous type. I am using Lightspeed v4. 多列(Multiple Columns) 语句描述:Linq使用Group By按CategoryID和SupplierID将产品分组。 说明:既按产品的分类,又按供应商分类。. The following example shows how to use an anonymous type to encapsulate a key that contains multiple values. Net guys) might have heard of the query language Linq ( Language Integrated Query ) used by Microsoft. However, the LINQ code is sufficiently different between Visual Basic and C# that it makes sense to discuss the two solutions independently. When you use an order-by operator before a group-by you end up only specifing the ordering of the items within each group. Products join category in uow. LINQ provides the default (and the most common) implementation of both of the operations, but sometimes you may need a slightly different behavior when grouping or ordering data (this article is motivated by a question on. Use HAVING clause to filter groups; In this tutorial, we are going to focus on the simplest form of the SELECT statement that allows you to query data from a single table. The SQL GROUP BY clause can be used in a SELECT statement to collect data across multiple records and group the results by one or more columns. We import the System. Look how simple is write the follow SQL Query in LINQ C#: With SQL: select city from students group by city order by city Now in LINQ C#: from student in Students group student. It's an awesome little library that allows you to dynamically generate LINQ expressions from strings, which is perfect for things like sorting collections by object property names passed as querystring parameters to web api controllers, it even allows you to sort by child object. But, like I said, if you just need a simple list with one record per group in a one-to-many query, this is an option that I discovered yesterday. Loop through Master-Detail Records using LINQ - Here’s an example of how to loop through Master-Detail Records using LINQ. When it is necessary to group by multiple keys, the selector must include an expression. Performance Surprises and Assumptions : GROUP BY vs. Also we will select only the top n rows in a group. Grouping by Expression Results: 17. Note that the SQL needs to end with semi-colon if you have multiple queries in the query window. How do you select multiple columns from a table while ensuring that one specific column doesn't contain duplicate values? You need to be a member in order to leave a comment [SQL] Select. A better solution is to use LINQ sub-expressions. Part 19 Group by multiple keys in linq - Duration: 10:38. In such cases we may need to group by multiple columns in the DataTable and create unique records in the table. For example, SQL database has no built-in Zip operation support. Linq; static class TestDictionary { static void Main() { Dictionary实现了一系列的扩展方法。 二、Linq中的关键字. One of the greatest benefits of LINQ to SQL and LINQ to Entities is navigation properties that allows queries across several tables, without the need to use explicit joins. So, for example if I have following items Date Order 08/10/2012 5 0. txt: RSR Stock Number/Manufacturer Part Number/UPC, Order Quantity. ItemId } into orderGroup Group By Multiple Columns - Stack Overflow; linq - Entity Framework T-Sql "having. I have two tables with a foreign key constraint how can I delete rows from both of them in one transaction? linq to SQL seems to call my deletes in the wrong order. It seems pretty basic, but the only way options I seem to have are aggregating a single column (Orders. SQL query is able to populate the dataset from the database but not able to retrieve a particular value from the dataset. After the OrderBy, add as many sorts as needed using the ThenBy function. UserID='varsha' group by rm. There are Different Types of SQL Joins which are used to query data from more than one tables. I'm trying to select multiple columns not in a group by using linq - c#. How do you select multiple columns from a table while ensuring that one specific column doesn't contain duplicate values? You need to be a member in order to leave a comment [SQL] Select. "Group By" clause is used for getting aggregate value (example: count of, sum of) in one or more columns with reference to a distinct column in a table. The Sales by Category query summarizes sales data ($ figures) for all products, sorted by category, using data from three tables (Products, Orders, and Order Details) and the Order Details Extended query (equivalent to a view). A few days ago I had a small issue concerning sorting. So for each row that the group by would return, I want to see numerous rows. City by student. It helps learning LINQ and convert existing SQL statements. Group mail table records into categories. In this post we will investigate this question and try to answer it in a didatic way, so we can refer to this post in the future. GROUP BY Syntax. I was trying the sql query below Grouping by more than one columns, but it gives syntax errors !!! Can somebody help me convert this query to LINQ ? select rl. Gallery items can be null (it is coming through a service so I am unable to change this). I am using Lightspeed v4. Does a Group By gaurantee that output data is sorted? the output data will be sorted on the Group By columns in order, even if there is NO Order By clause. SELECT ID1, ID2, Value1, MAX(Value2), MAX(Date1) FROM MyTable i GROUP BY ID1, ID2, Value1. I'm a big fan of LINQ, and one of my favorite extension methods is GroupBy. IN Clause with WHERE clause not getting proper results in SQL Server. UPDATED: added a new column combining the Date and Time column which are string fields into DateTimeCombined column which is a DateTime field. function() The comparator function used to determine the relative order of value pairs. This GROUP BY clause follows the WHERE clause in a SELECT statement and precedes the ORDER BY clause. ORDER BY Several Columns Example. SupplierID } into g select new { g. In both query-syntax and method-syntax, you can easily perform multiple orderings. Order by with dynamic columns in LINQ c# September 14, 2016 Hi Guys, sometimes we need to sort the data dynamically with dynamic column, suppose we are sowing data in grid and after click on column data should be sort, on first click it should be descending and on again click it should be ascending etc. MULTIPLE-TABLE SELECT. NET Web API https://www. To sort descending, use the Descending keyword. Lets have players. This SELECT example joins two tables to gives us a result set that displays the order_id from the orders table and the last_name from the customers table. Lets take a scenario when you fill out an online form. Product_Id,Products. EffectiveDate <= @Time GROUP BY PersonnelBaseID @Time is an input parameter; assume tkp_PersonnelDetails is a list of objects in C#. NET, Entity Framework, LINQ to SQL, NHibernate / Group by and Order by in the same expression Group by and Order by in the same expression [Answered] RSS 3 replies. Apply Multiple Order by on a list using LINQ. The second key value is a Boolean that specifies whether the student scored over 85 on the first exam. It's an awesome little library that allows you to dynamically generate LINQ expressions from strings, which is perfect for things like sorting collections by object property names passed as querystring parameters to web api controllers, it even allows you to sort by child object. I stumbled across the Dynamic LINQ Library today and can't figure out why more people aren't talking about it. Group by in LINQ. Intersect(query. Now, what if you want to sort based on multiple columns. CategoryName } into g. Re: Joins and Left Outer Joins in LINQ–Do you want groups with that? This site is excellent and so is how the subject matter was explained. To find out more, including how to control cookies, see here. Results set contains three items since three distinct values existed in first column in the original set. The second key value is a Boolean that specifies whether the student scored over 85 on the first exam. I want to return multiple Sum columns LINQ SUM multiple remove grouping Linq using Sum() with NO GROUP BY. Net applications and web sites. Let's consider the three more common functions used. Linq; namespace AbundantCode { internal class Program { //How to Remove Duplicates and Get […]. Grouping Data Table data with single columns. This example shows how to calculate sum for each group. LINQ with lambda - How do I orderby after groupby? What I WANT to do is also order the clients (the group) by milestone date ascending so that the Client with the. Rich Query for DataSet- An Introduction to LINQ to DataSet tables and columns to store and represent the cached data. The “Include” method will prompt L2E to create a left outer join and ensure that the order and all of the line items are fetched at once. You can sort by one column in ascending order and another column in descending order. The following SQL statement selects all customers from the "Customers" table, sorted by the "Country" and the "CustomerName" column. For using the group as well with the methods that follow the Select method, the anonymous type contains the group as well. What I want is a "GroupBy" clause which would get me a Dictionary (Of String, String) from this collection where the key is the. Elements that are associated with matching key values are included in the same group. However, instead of grouping by one property, we need to create a new anonymous object and group by that object. How Group by works with C# Linq. You are here: Home / Uncategorized / How to combine values from multiple rows of a single column (T-SQL, Microsoft SQL Server, FOR XML PATH, CSV ). just use one entry in the top level array), or multi-column ordering to the nth column (multiple entries in the array). It's FREE too :) ASP. In other words, we can say Zip operation on multiple sequences. using multiple. "Group By" clause is used for getting aggregate value (example: count of, sum of) in one or more columns with reference to a distinct column in a table. QuinStreet. The grouping is handled with the LINQ group by statement, and here we choose the Genre field as our key to group by. The ordering of the groups themselves are non-deterministic as per SQL behavior. private void GetEmployee() {. The usual case is that all column names in an aggregate query are either arguments to aggregate functions or else appear in the GROUP BY clause. The crossed methods are not supported by LINQ to Entities (the list provided by MDSN is not up to date), because they cannot be translated to proper SQL database operations. Linq Injection – From Attacking Filters to Code Execution Some of you (especially the. RewardType,sum(rl. A query expression can create a new data structure. 21637 (nightly 16 Oct 2012) on the Nortwind database. When we designed our data model using the LINQ to SQL data designer above we defined five data model classes: Product, Category, Customer, Order and OrderDetail. The need to combine results in multiple SQL Server tables for producing a list of records or summary reports are often a challenge to us as a developer. Loading Unsubscribe from Jamie King? Cancel Unsubscribe. This example shows how to calculate sum for each group. It is because it looks at all of the columns you specify and determines if in any given records are the same as another record. In the example below the 'group' is the office location, which is based on the information in the third column (which is set to hidden). Categories on product. Highest Value in each Group using LINQ - In this post, I will show you how to fetch the maximum value in each Group using LINQ. Now we select our subsets into the Group object, which will consist of a key and a collection of each book which matches this key. NET Framework > Visual C#. Product_Id = Products. in need to order by multiple columns and my first instinct was to use an && operator just like you do when. You are here: Home / Uncategorized / How to combine values from multiple rows of a single column (T-SQL, Microsoft SQL Server, FOR XML PATH, CSV ). Simple Row_Number() simulation. Linqer is a SQL to LINQ conversion tool. Query Expression Syntax Examples: Ordering (LINQ to DataSet) 03/30/2017; 4 minutes to read +6; In this article. Key, g }; 语句描述:Linq使用Group By按CategoryID和SupplierID将产品分组。 说明:既按产品的分类,又按供应商分类。在by后面,new出来一个匿名类。. Net) that extends these languages with query operators and some other features that make it possible to integrate queries in the languages. So far in this tutorial, we have seen how to sort a single column (with and without headers). I use LINQ to SQL to get all products from a DB table and sort them by two fields – IsFavorite (boolean) and AddedOn (datetime). The following example shows how to use an anonymous type to encapsulate a key that contains multiple values. To understand how both ways work to give the same result, you can use the OzCode VS extension’s LINQ feature: OrderBy with multiple orderings. What is LINQ GroupBy Operator? The LINQ GroupBy operator is different and unique in its own way in sense that it is the only operator that takes a flat sequence of items, organize that sequence into categories or groups and return groups of sequences. A GROUP BY clause can contain two or more columns—or, in other words, a grouping can consist of two or more columns. The group by statement is usually seen with an aggregate function, used to extrapolate useful information from the data. As fore mentioned, these query methods (also called standard query …. Rich Query for DataSet- An Introduction to LINQ to DataSet tables and columns to store and represent the cached data. Using the group by statement with multiple columns is useful in many different situations – and it is best illustrated by an example. When you refer to this column in your ORDER BY clause, you have to use this new. If you were to put in multiple column names like, SELECT DISTINCT username, password, you would see 4 records. Now, what if you want to sort based on multiple columns. Linda is an HR in a small private firm. It gets unique elements. This method transforms a collection into groups. To Think in LINQ. For more information, see Section 12. LINQ method Max can be used also on collection of custom type Max with Group By. Group by and order by for linked tables: 16. You can use the Group By clause to break the results of a query into groups. OVER allows you to get aggregate information without using a GROUP BY. Showing how to exploit Group/By/Into is the point of this column. This way you can select and range of values to group and give the impression in your requirement example. SELECT year, month, COUNT(*) AS count FROM tutorial. Having problems getting it done in Linq all the examples I can find only group by a single column. I've always stayed away from first/first or default because I never knew how to set the default and I'd rather check for null values than catch exceptions. Elements that are associated with matching key values are included in the same group. Give the expression an alias in the output column list and refer to the alias in the GROUP BY clause: 18. So, let’s start by creating one temporary DataTable. CustomerName, order. LINQ with lambda - How do I orderby after groupby? What I WANT to do is also order the clients (the group) by milestone date ascending so that the Client with the. So I want you to hear it first from me – to avoid any trouble with it in the future! When you use ORDER BY and GROUP BY, you can of course use column names (as we have done so far) but you can also use column numbers (that’s the new thing). Simple Row_Number() simulation. LINQ Order By Examples in C# The order by clause in LINQ is easy to learn due to its close resemblance to the T-SQL syntax. I would like to know how I could dynamically order by each group and its contents. I have taken the example of one Department containing multiple Employees. 3, “MySQL Handling of GROUP BY”. So what the LINQ should do is group by name column and get the row for each name that has the earliest date+time. The order of rows returned from the SELECT statement is unpredictable therefore the “first” row of each group of the duplicate is also unpredictable. So, for example if I have following items Date Order 08/10/2012 5 0. 04 [Linq] 기초통계량 구하기 (0) 2015. In both query-syntax and method-syntax, you can easily perform multiple orderings. Having problems getting it done in Linq all the examples I can find only group by a single column. When you use an order-by operator before a group-by you end up only specifing the ordering of the items within each group. Sum with Group By. Dear Experts I would want to join multiple tables in a linq query and the group by variables from different tables using a LINQ. Using the group by statement with multiple columns is useful in many different situations – and it is best illustrated by an example. To illustrate this point, consider the data in the SALES table. C# Linq Group By on multiple columns. C# LINQ: Combine Multiple Sequences In Parallel In this article, we will see how to join multiple arrays, lists or collections by order with LINQ. We can achieve the same in multiple ways such as writing multiple group by clause recursively for the various keys or by creating an in memory buckets to group programmatically. Today, I was required to order a list of records based on a Name and then ID. The first OrderBy function of the list is the main sort. Suppose we have a table shown below called Purchases. com Normally while working on a project, I avoid the use of LINQ query and prefer to do all the grouping and ordering operation in the SQL procedure itself but recently, I came across a situation where I need to perform multiple order by operation on a list i. But, if the column I want is not even present, a default value should be used instead. ORDER BY clause orders the result set of a SQL query for a particular or specific set of columns provided in ORDER BY clause. How Group by works with C# Linq. Now what I want to do, is to GroupBy Date and count orders. SQL ORDER BY examples. Product_Id =270 group by OrderLines. You can now more easily create a group of objects on arbitrary criterion than ever before. Jamie King showing how to group data by multiple criteria. So far in this tutorial, we have seen how to sort a single column (with and without headers). ORDER BY [column/columns] Aggregate Functions. It is easy for humans to read and write. The following example shows how to use an anonymous type to encapsulate a key that contains multiple values. Products group p by new { p. We will also provide some examples on combinations of these columns and. Both the tables have columns Column1 and Column2. CategoryID, p. The GROUP BY makes the result set in summary rows by the value of one or more columns. The following question is not new, but keeps being repeated over time. The use case was pretty typical - aggregate some pre-filtered set of invoices by the product sold, count how many sales were there for each product, order the data by total sales value and take. SQL Inner Join and Group by Clause is described as follows, SQL -select Products. FirstOrDefault() ) //To filter out. The SQL GROUP BY Statement. group order by new { order. UPDATED: added a new column combining the Date and Time column which are string fields into DateTimeCombined column which is a DateTime field. For each Id and Code, if message size exceeds column MAX size, then the message is split and stored in multiple rows using SequenceNumber in incremental form. [Linq] DataTable에서 Linq 사용하기 Group By (0) 2015. On the other hand adding every single column from the select clause to the group by will result in useless group clause that will return a group for each row in your table. Team total score is sum of score of all players in the team. SQL Group By: SQL Having: DISTINCT operates on a single column. The SQL GROUP BY clause is used in collaboration with the SELECT statement to arrange identical data into groups. Key , g };. While working with Entity Framework LINQ people ususally get struck on how to use joins, group by cluase, count etc. In this example I will explain grouping using LINQ with following sample examples. Does anyone know how I might accomplish this?. Sort by multiple fields with LINQ October 7, 2010. last_name ORDER BY l. To find out more, including how to control cookies, see here. each( array, callback ) Returns: Object Description: A generic iterator function, which can be used to seamlessly iterate over both objects and arrays.