Often you may want to attach multiple DataSources. This sample shows how to:
- First get all the data from the current App using
GetAppSource()
- Then get a
EntityTypeFilter
from ToSic.Eav.DataSources
- When creating the filter, also
attach
the initial app DataSource...
- ...and give the filter the parameter
TypeName = "Books"
- Count the data in both DataSources
- Loop through the final items in the filter DataSource
Note that you can do much more, best check out the docs.
⬇️ Result | Source ➡️
Statistics
- App Item Count (unfiltered): 1673
- Books Item Count (filtered): 4
- Authors Item Count (filtered): 6
List of Persons from the DataSource
-
Hitchhikers Guide to the Galaxy (Books)
-
Good Omens (Books)
-
Phishing for Phools (Books)
-
The Last Continent (Books)
-
Douglas (Persons)
-
Terry (Persons)
-
Neil (Persons)
-
George (Persons)
-
Raphael (Persons)
-
Ed (Persons)
@inherits Custom.Hybrid.Razor14
@using ToSic.Razor.Blade
@using System.Linq
@using ToSic.Eav.DataSources
@{
// First get the root data source - the App with all data
var appDs2 = Kit.Data.GetAppSource();
// Now create a Type-Filter and tell it to only keep Books / Authors
var books2 = Kit.Data.GetSource<EntityTypeFilter>(attach: appDs2, parameters: new { TypeName = "Books" });
var authors2 = Kit.Data.GetSource<EntityTypeFilter>(attach: appDs2, parameters: new { TypeName = "Persons" });
// The following lines are just spread for easier documentation
// Usually you would write in inline
var dataSourceLinks2 = books2.Link // Get the link to the books
.Add(authors2.Link // Add the author2 link
.Rename(inName: "Stream2" // but rename the link so it's attached as "Stream2"
)
);
var merged2 = Kit.Data.GetSource<StreamMerge>(attach: dataSourceLinks2);
}
<h3>Statistics</h3>
<ul>
<li>App Item Count (unfiltered): @appDs2.List.Count()</li>
<li>Books Item Count (filtered): @books2.List.Count()</li>
<li>Authors Item Count (filtered): @authors2.List.Count()</li>
</ul>
<h3>List of Persons from the DataSource</h3>
<ul>
@foreach (var item in AsList(merged2)) {
<li>
@item.EntityTitle (@item.EntityType)
</li>
}
</ul>