Book Image

Cross-platform UI Development with Xamarin.Forms

By : Paul Johnson
Book Image

Cross-platform UI Development with Xamarin.Forms

By: Paul Johnson

Overview of this book

Table of Contents (22 chapters)
Cross-platform UI Development with Xamarin.Forms
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
In the Beginning…
Index

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:

  1. From the SQLite database, grab all messages with a parent id of -1.

  2. Using the initial list, perform the following steps:

    1. Iterate through the list.

    2. From the SQLite database, grab messages where parentid == id and store it in a List collection.

  3. On the List, use LINQ to order by DateTime.

  4. 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...