LINQ me up baby – yeah!
LINQ gives the developer the power of SQL but for collections. It is not uncommon to order data coming from an SQL database for given parameters (such as searching on a property and outputting the data based on surname and the output ordered DateTime
, then the first letter of the first name property), but in terms of collections prior to LINQ manipulation, it literally meant iterating through each piece of data.
In terms of our message collection, we can construct our lists like the following:
From the SQLite database, grab all messages with a parent id of
-1
.Using the initial list, perform the following steps:
Iterate through the list.
From the SQLite database, grab messages where
parentid == id
and store it in aList
collection.
On the
List
, use LINQ to order byDateTime
.Store the ids in a
Dictionary
collection.
Simple! At the end, there will be a Dictionary
with the initial ID followed by the List
of IDs.
The code would look like the following. In this example, DBManager...