Custom Dynamic DataSources - Multiple Lists/Streams
Requirements
DataSources can have one or more streams.
Two Streams: Default and Settings
The default stream is called Default
so you don't need to specify it.
In the following example, we have a second stream called Settings
.
Data in the stream "Settings"
- PageSize: 50
- ShowStuff: True
List of Data in the Default stream (5)
- Hello from ListMultiStream (1 / 93cb671c-ee43-42d0-ad88-08c4af0e527b) - Fav Number: 2742
- Hello from ListMultiStream (2 / 4b9cd9c2-f5d2-4fab-b23c-0d62e3f902f3) - Fav Number: 2742
- Hello from ListMultiStream (3 / 6bd32be0-c636-4ecc-b1f7-e907b1759505) - Fav Number: 2742
- Hello from ListMultiStream (4 / d6162ade-5ff6-4736-bd2c-6088829c8858) - Fav Number: 2742
- Hello from ListMultiStream (5 / bdc59ac6-f6bf-4a16-aaf2-c1f3bcd3029d) - Fav Number: 2742
Two Streams, Prepared at same time
In some cases it makes sense to provide multiple streams which were processed at the same time.
For example, when splitting data or when providing a stream Folders
and Files
which are still related.
The following sample takes the original Persons
and splits them into odd/even streams in one preparation step.
List of Data in the All stream (6)
- Douglas (#4001)
- Terry (#4002)
- Neil (#4003)
- George (#4007)
- Raphael (#4011)
- Ed (#4012)
List of Data in the Odd stream (4)
- Douglas (#4001)
- Neil (#4003)
- George (#4007)
- Raphael (#4011)
List of Data in the Even stream (2)
- Terry (#4002)
- Ed (#4012)
Source Code of this file
Below you'll see the source code of the file. Note that we're just showing the main part, and hiding some parts of the file which are not relevant for understanding the essentials. Click to expand the code
@inherits Custom.Hybrid.Razor14 @using ToSic.Razor.Blade; @using System.Linq; @using ToSic.Eav.DataSources; <!-- unimportant stuff, hidden --> <h2>Custom Dynamic DataSources - Multiple Lists/Streams</h2> <div @Sys.PageParts.InfoWrapper()> @Html.Partial("../shared/DefaultInfoSection.cshtml") <div @Sys.PageParts.InfoIntro()> <p> DataSources can have one or more streams. </p> </div> </div> Two Streams: Default and Settings The... <!-- unimportant stuff, hidden --> @{ // Create the Dynamic DataSource with the name "ListMultiStream" var multiStream = Kit.Data.GetSource(name: "ListMultiStream"); var settings = AsDynamic(multiStream["Settings"].List.FirstOrDefault()); } <h3>Data in the stream "Settings"</h3> <ul> <li>PageSize: @settings.PageSize</li> <li>ShowStuff: @settings.ShowStuff</li> </ul> <h3>List of Data in the Default stream (@multiStream.List.Count())</h3> <ul> @foreach (var item in AsList(multiStream)) { <li> <strong>@item.Title</strong> (@item.EntityId / @item.EntityGuid) - Fav Number: @item.FavoriteNumber </li> } </ul> Two Streams, Prepared at same time In... <!-- unimportant stuff, hidden --> @{ var oddEven = Kit.Data.GetSource(name: "SplitOddEven", attach: App.Data["Persons"]); var all = oddEven.List; var odd = oddEven["Odd"].List; var even = oddEven["Even"].List; } <h3>List of Data in the All stream (@all.Count())</h3> <ul> @foreach (var item in AsList(all)) { <li> <strong>@item.EntityTitle</strong> (#@item.EntityId) </li> } </ul> <h3>List of Data in the Odd stream (@odd.Count())</h3> <ul> @foreach (var item in AsList(odd)) { <li> <strong>@item.EntityTitle</strong> (#@item.EntityId) </li> } </ul> <h3>List of Data in the Even stream (@even.Count())</h3> <ul> @foreach (var item in AsList(even)) { <li> <strong>@item.EntityTitle</strong> (#@item.EntityId) </li> } </ul> @* Footer *@ @Html.Partial("../Shared/Layout/FooterWithSource.cshtml", new { Sys = Sys })