LINQ Relationships - Children, Parents, Grandchildren, ...
Switch to Typed (2sxc 16+) Selected: Dynamic (Razor14 or below)
This example shows the books, and we want to LINQ on the Authors. We must tell the compiler it's a list, so that LINQ can use Select(...)
.
⬇️ Result | Source ➡️
- Hitchhikers Guide to the Galaxy by Douglas Adams
- Good Omens by Neil Gaiman, Terry Pratchett
- Phishing for Phools by George Akerlof
- The Last Continent by Terry Pratchett
This example shows Z-A ordering, where we count the authors to sort.
⬇️ Result | Source ➡️
- Good Omens by Neil Gaiman,Terry Pratchett (2 author)
- Hitchhikers Guide to the Galaxy by Douglas Adams (1 author)
- Phishing for Phools by George Akerlof (1 author)
- The Last Continent by Terry Pratchett (1 author)
This example will group the books by the Authors
property. This example doesn't give us what we want, because authors that exist in sets and alone are grouped separately.
⬇️ Result | Source ➡️
-
Group
- Hitchhikers Guide to the Galaxy by Douglas Adams
-
Group
- Good Omens by Neil Gaiman,Terry Pratchett
-
Group
- Phishing for Phools by George Akerlof
-
Group
- The Last Continent by Terry Pratchett
Let's do it better, and group by each Author individually
⬇️ Result | Source ➡️
-
Author: Douglas Adams
- Hitchhikers Guide to the Galaxy by Douglas Adams
-
Author: Neil Gaiman
- Good Omens by Neil Gaiman,Terry Pratchett
-
Author: Terry Pratchett
- Good Omens by Neil Gaiman,Terry Pratchett
- The Last Continent by Terry Pratchett
-
Author: George Akerlof
- Phishing for Phools by George Akerlof
In this example, we'll start with the authors list. This is probably not ideal - as some people are not authors, but it's a good learning example. To find the books we have to navigate through Parents(...)
because in our data-model, the books reference authors, not the authors to books.
⬇️ Result | Source ➡️
-
Douglas Adams
- Hitchhikers Guide to the Galaxy
-
Terry Pratchett
- Good Omens co-authored by Neil Gaiman
- The Last Continent
-
Neil Gaiman
- Good Omens co-authored by Terry Pratchett
-
George Akerlof
- Phishing for Phools
-
Raphael Müller (not an author)
-
Ed Hardy
This example first gets book, checks the authors and checks if they have awards with LINQ Any()
.
⬇️ Result | Source ➡️
- Hitchhikers Guide to the Galaxy with Hugo Award,Inkpot Award (2 awards)
- Phishing for Phools with Nobel Peace Prize (1 awards)
And now the opposite list, so all books which don't contain one of the books with authors. It gets the "other" books by filtering the list to exclude the ones it found first. That demonstrates how to use Contains(x as object)
. The Contains(...)
cannot work with dynamic
, so we must tell it it's an object for it to work.
⬇️ Result | Source ➡️
- Good Omens
- The Last Continent
Now let's do the same, but using GroupBy
to group by awarded authors and not-awarded authors:
⬇️ Result | Source ➡️
-
Authors with Awards: True
- Hitchhikers Guide to the Galaxy
- Phishing for Phools
-
Authors with Awards: False
- Good Omens
- The Last Continent
Find Parents of Authors - Things that point to Authors
In this example, we'll start with the authors list. This is probably not ideal - as some people are not authors, but it's a good learning example. To find the books we have to navigate through Parents(...)
because in our data-model, the books reference authors, not the authors to books.
⬇️ Result | Source ➡️
-
Douglas Adams
- Hitchhikers Guide to the Galaxy
-
Terry Pratchett
- Good Omens co-authored by Neil Gaiman
- The Last Continent
-
Neil Gaiman
- Good Omens co-authored by Terry Pratchett
-
George Akerlof
- Phishing for Phools
-
Raphael Müller (not an author)
-
Ed Hardy