App
Requirements
Data Sources Tutorial - use in C# / Razor Code
DataSources are the magic backbone of 2sxc. They can get data, filter it, sort it, and more. These samples show you how to use them in code (instead of in VisualQuery).
- You can use the IDataService with
Kit.Data
in your C# code to get DataSource Objects. A common scenario is when you need to configure the parameters in ways that are not possible in the UI. - Such DataSources can also be linked together (attached) so the output of one DataSource becomes the input of another.
- You can also provide
options
to give each DataSource it's configuration.
Data Sources Tutorial - Basic Use
To get started, let's look at some samples to just use a DataSource in code.
Use Kit.Data.GetSource<Csv>
to create a DataSource reading CSV data. This sample shows how to:
- Use
Kit.Data.GetSource<DataSourceName<
to get the desired DataSource - Get a
Csv
DataSource fromToSic.Eav.DataSources
- When creating the source, also provide settings for
FilePath
andDelimiter
- Loop through the items
⬇️ Result | Source ➡️
List of Data in the CSV DataSource (4)
- 2sxc (A neat CMS extension for DNN)
- Koi (System to coordinate the CSS-Framework between theme and modules.)
- Razor Blade (Helpers for common Razor task)
- Image Resizer (Automatic, amazing image Resizer)
Use Kit.Data.GetAppSource
and Kit.Data.GetSource<T>
to create data sources. This sample shows how to:
- First get all the data from the current App using
GetAppSource()
- Then get a
EntityTypeFilter
fromToSic.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
⬇️ Result | Source ➡️
Statistics
- App Item Count (unfiltered): 1604
- Books Item Count (filtered): 4
List of Persons from the DataSource
- Hitchhikers Guide to the Galaxy
- Good Omens
- Phishing for Phools
- The Last Continent
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
fromToSic.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): 1604
- 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)
Data Sources Tutorial - Use GetQuery
Kit.Data.GetQuery()
should be used to retrieve a query. It also allows us to pass in parameters if the query supports it. The following demos all use this query. TODO: PIC of query
Use Kit.Data.GetQuery("QueryName")
to get a Query DataSource. This first sample does not use parameters so the sorting happens on whatever was set as default.
⬇️ Result | Source ➡️
List of Persons from the DataSource
- Douglas Adams
- George Akerlof
- Neil Gaiman
- Ed Hardy
- Raphael Müller (not an author)
- Terry Pratchett
View Configuration
This is how this view would be configured for this sample.
- Query: GetQueryDemoAuthorsSortedOqtane
No details yet for GetQueryDemoAuthorsSortedOqtane
This will also provide parameters to change how it is sorted. Note that these parameters only work, because the Query expects these.
⬇️ Result | Source ➡️
List of Persons from the DataSource
- Terry Pratchett
- Raphael Müller (not an author)
- Neil Gaiman
- George Akerlof
- Ed Hardy
- Douglas Adams
View Configuration
This is how this view would be configured for this sample.
- Query: GetQueryDemoAuthorsSortedOqtane
No details yet for GetQueryDemoAuthorsSortedOqtane