Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
iJungleboy committed May 8, 2024
1 parent 0fc5da0 commit a627418
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,6 @@ In some scenarios, your code will want to work with this data as if it were a da

There are a few ways to do this.

## Basic using As and AsList

```csharp
// Get all and convert to Person
var people = AsList<Person>(App.Data.GetStream("Person"));
// Get all and convert the first to person - will be null if there is no data
var onePerson = As<Person>(App.Data.GetStream("Person"));
// Get all, convert, then find the one with the ID - null if no match
var person45 = AsList<Person>(App.Data.GetStream("Person")).FirstOrDefault(p => p.Id == 45);
// Get one and convert to Person - null if no match; faster
var person72 = As<Person>(App.Data.GetStream("Person").List.FirstOrDefault(e => e.EntityId = 72));
```

This all works, but it's a bit verbose and you will sometimes do too much work, which is not ideal for performance.

## New using GetAll and GetOne

The most common operations will be to get all or get a specific item.
Expand All @@ -41,6 +26,21 @@ var person72 = App.Data.GetOne<Person>(72);
var personFromGuid = App.Data.GetOne<Person>(Guid.Parse("..."));
```

## Basic using As and AsList

```csharp
// Get all and convert to Person
var people = AsList<Person>(App.Data.GetStream("Person"));
// Get all and convert the first to person - will be null if there is no data
var onePerson = As<Person>(App.Data.GetStream("Person"));
// Get all, convert, then find the one with the ID - null if no match
var person45 = AsList<Person>(App.Data.GetStream("Person")).FirstOrDefault(p => p.Id == 45);
// Get one and convert to Person - null if no match; faster
var person72 = As<Person>(App.Data.GetStream("Person").List.FirstOrDefault(e => e.EntityId = 72));
```

This all works, but it's a bit verbose and you will sometimes do too much work, which is not ideal for performance.

## Good to Know

* To make the magic work, `GetAll(...)` and `GetOne(...)` will use the **class name** to determine the stream it should retrieve.
Expand Down
10 changes: 5 additions & 5 deletions docs/api/dot-net/ToSic.Sxc.Engines.EngineBase.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ <h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>

<h1 id="ToSic_Sxc_Engines_EngineBase" data-uid="ToSic.Sxc.Engines.EngineBase" class="text-break">
Class EngineBase
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Engines/EngineBase.cs/#L19"><i class="bi bi-code-slash"></i></a>
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Engines/EngineBase.cs/#L15"><i class="bi bi-code-slash"></i></a>
</h1>

<div class="facts text-secondary">
Expand Down Expand Up @@ -172,7 +172,7 @@ <h2 class="section" id="constructors">Constructors

<h3 id="ToSic_Sxc_Engines_EngineBase__ctor_ToSic_Sxc_Engines_EngineBase_MyServices_System_Object___" data-uid="ToSic.Sxc.Engines.EngineBase.#ctor(ToSic.Sxc.Engines.EngineBase.MyServices,System.Object[])">
EngineBase(MyServices, object[])
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Engines/EngineBase.cs/#L66"><i class="bi bi-code-slash"></i></a>
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Engines/EngineBase.cs/#L62"><i class="bi bi-code-slash"></i></a>
</h3>

<div class="markdown level1 summary"><p>Empty constructor, so it can be used in dependency injection</p>
Expand Down Expand Up @@ -210,7 +210,7 @@ <h2 class="section" id="methods">Methods

<h3 id="ToSic_Sxc_Engines_EngineBase_Init_ToSic_Sxc_Blocks_Internal_IBlock_" data-uid="ToSic.Sxc.Engines.EngineBase.Init(ToSic.Sxc.Blocks.Internal.IBlock)">
Init(IBlock)
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Engines/EngineBase.cs/#L70"><i class="bi bi-code-slash"></i></a>
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Engines/EngineBase.cs/#L66"><i class="bi bi-code-slash"></i></a>
</h3>

<div class="markdown level1 summary"></div>
Expand Down Expand Up @@ -241,7 +241,7 @@ <h4 class="section">Parameters</h4>

<h3 id="ToSic_Sxc_Engines_EngineBase_Render_ToSic_Sxc_Blocks_Internal_RenderSpecs_" data-uid="ToSic.Sxc.Engines.EngineBase.Render(ToSic.Sxc.Blocks.Internal.RenderSpecs)">
Render(RenderSpecs)
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Engines/EngineBase.cs/#L108"><i class="bi bi-code-slash"></i></a>
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Engines/EngineBase.cs/#L104"><i class="bi bi-code-slash"></i></a>
</h3>

<div class="markdown level1 summary"><p>Renders a template, returning a string with the rendered template.</p>
Expand Down Expand Up @@ -279,7 +279,7 @@ <h4 class="section">Returns</h4>
</article>

<div class="contribution d-print-none">
<a href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Engines/EngineBase.cs/#L19" class="edit-link">Edit this page</a>
<a href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Engines/EngineBase.cs/#L15" class="edit-link">Edit this page</a>
</div>


Expand Down
18 changes: 9 additions & 9 deletions docs/api/dot-net/ToSic.Sxc.Services.IEditService.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ <h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>

<h1 id="ToSic_Sxc_Services_IEditService" data-uid="ToSic.Sxc.Services.IEditService" class="text-break">
Interface IEditService
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Services/EditService/IEditService.cs/#L24"><i class="bi bi-code-slash"></i></a>
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Services/EditService/IEditService.cs/#L20"><i class="bi bi-code-slash"></i></a>
</h1>

<div class="facts text-secondary">
Expand Down Expand Up @@ -165,7 +165,7 @@ <h2 class="section" id="properties">Properties

<h3 id="ToSic_Sxc_Services_IEditService_Enabled" data-uid="ToSic.Sxc.Services.IEditService.Enabled">
Enabled
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Services/EditService/IEditService.cs/#L38"><i class="bi bi-code-slash"></i></a>
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Services/EditService/IEditService.cs/#L34"><i class="bi bi-code-slash"></i></a>
</h3>

<div class="markdown level1 summary"><p>If editing is enabled or not</p>
Expand Down Expand Up @@ -202,7 +202,7 @@ <h2 class="section" id="methods">Methods

<h3 id="ToSic_Sxc_Services_IEditService_Attribute_System_String_System_Object_" data-uid="ToSic.Sxc.Services.IEditService.Attribute(System.String,System.Object)">
Attribute(string, object)
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Services/EditService/IEditService.cs/#L261"><i class="bi bi-code-slash"></i></a>
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Services/EditService/IEditService.cs/#L257"><i class="bi bi-code-slash"></i></a>
</h3>

<div class="markdown level1 summary"><p>Generate an HTML attribute by converting the value to JSON</p>
Expand Down Expand Up @@ -247,7 +247,7 @@ <h4 class="section">Returns</h4>

<h3 id="ToSic_Sxc_Services_IEditService_Attribute_System_String_System_String_" data-uid="ToSic.Sxc.Services.IEditService.Attribute(System.String,System.String)">
Attribute(string, string)
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Services/EditService/IEditService.cs/#L252"><i class="bi bi-code-slash"></i></a>
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Services/EditService/IEditService.cs/#L248"><i class="bi bi-code-slash"></i></a>
</h3>

<div class="markdown level1 summary"><p>Generate an HTML attribute by converting the value to JSON</p>
Expand Down Expand Up @@ -292,7 +292,7 @@ <h4 class="section">Returns</h4>

<h3 id="ToSic_Sxc_Services_IEditService_ContextAttributes_ToSic_Eav_Data_ICanBeEntity_ToSic_Lib_Coding_NoParamOrder_System_String_System_String_System_Nullable_System_Guid__System_String_System_Int32_" data-uid="ToSic.Sxc.Services.IEditService.ContextAttributes(ToSic.Eav.Data.ICanBeEntity,ToSic.Lib.Coding.NoParamOrder,System.String,System.String,System.Nullable{System.Guid},System.String,System.Int32)">
ContextAttributes(ICanBeEntity, NoParamOrder, string, string, Guid?, string, int)
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Services/EditService/IEditService.cs/#L175"><i class="bi bi-code-slash"></i></a>
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Services/EditService/IEditService.cs/#L171"><i class="bi bi-code-slash"></i></a>
</h3>

<div class="markdown level1 summary"><p>Get html-attributes to mark the current context
Expand Down Expand Up @@ -361,7 +361,7 @@ <h4 class="section" id="ToSic_Sxc_Services_IEditService_ContextAttributes_ToSic_

<h3 id="ToSic_Sxc_Services_IEditService_Enable_ToSic_Lib_Coding_NoParamOrder_System_Nullable_System_Boolean__System_Nullable_System_Boolean__System_Nullable_System_Boolean__System_Nullable_System_Boolean__System_Nullable_System_Boolean__System_Nullable_System_Boolean__" data-uid="ToSic.Sxc.Services.IEditService.Enable(ToSic.Lib.Coding.NoParamOrder,System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean})">
Enable(NoParamOrder, bool?, bool?, bool?, bool?, bool?, bool?)
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Services/EditService/IEditService.cs/#L237"><i class="bi bi-code-slash"></i></a>
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Services/EditService/IEditService.cs/#L233"><i class="bi bi-code-slash"></i></a>
</h3>

<div class="markdown level1 summary"><p>Ensure that the UI will load the correct assets to enable editing. See <a class="xref" href="../../net-code/razor/edit.enable.html"> Method in C# Razor (Deprecated)</a></p>
Expand Down Expand Up @@ -433,7 +433,7 @@ <h4 class="section" id="ToSic_Sxc_Services_IEditService_Enable_ToSic_Lib_Coding_

<h3 id="ToSic_Sxc_Services_IEditService_TagToolbar_System_Object_ToSic_Lib_Coding_NoParamOrder_System_String_System_String_System_Object_System_Object_System_Object_System_Object_" data-uid="ToSic.Sxc.Services.IEditService.TagToolbar(System.Object,ToSic.Lib.Coding.NoParamOrder,System.String,System.String,System.Object,System.Object,System.Object,System.Object)">
TagToolbar(object, NoParamOrder, string, string, object, object, object, object)
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Services/EditService/IEditService.cs/#L144"><i class="bi bi-code-slash"></i></a>
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Services/EditService/IEditService.cs/#L140"><i class="bi bi-code-slash"></i></a>
</h3>

<div class="markdown level1 summary"><p>Generate a toolbar attribute inside an html-tag <br>
Expand Down Expand Up @@ -512,7 +512,7 @@ <h4 class="section" id="ToSic_Sxc_Services_IEditService_TagToolbar_System_Object

<h3 id="ToSic_Sxc_Services_IEditService_Toolbar_System_Object_ToSic_Lib_Coding_NoParamOrder_System_String_System_String_System_Object_System_Object_System_Object_System_Object_" data-uid="ToSic.Sxc.Services.IEditService.Toolbar(System.Object,ToSic.Lib.Coding.NoParamOrder,System.String,System.String,System.Object,System.Object,System.Object,System.Object)">
Toolbar(object, NoParamOrder, string, string, object, object, object, object)
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Services/EditService/IEditService.cs/#L90"><i class="bi bi-code-slash"></i></a>
<a class="header-action link-secondary" title="View source" href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Services/EditService/IEditService.cs/#L86"><i class="bi bi-code-slash"></i></a>
</h3>

<div class="markdown level1 summary"><p>Generate a toolbar tag - must be used in normal html, not as an attribute. <br>
Expand Down Expand Up @@ -591,7 +591,7 @@ <h4 class="section" id="ToSic_Sxc_Services_IEditService_Toolbar_System_Object_To
</article>

<div class="contribution d-print-none">
<a href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Services/EditService/IEditService.cs/#L24" class="edit-link">Edit this page</a>
<a href="https://github.com/2sic/2sxc/blob/develop/Src/Sxc/ToSic.Sxc/Services/EditService/IEditService.cs/#L20" class="edit-link">Edit this page</a>
</div>


Expand Down
2 changes: 1 addition & 1 deletion docs/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -4342,7 +4342,7 @@
"net-code/api-typed-strong/app-data-typed.html": {
"href": "net-code/api-typed-strong/app-data-typed.html",
"title": "Strong Typed App Data in 2sxc 17+ | 2sxc 17 for Dnn and Oqtane",
"keywords": "Strong Typed App Data in 2sxc 17+ The App.Data object provides a DataSource to all the data inside the App. In some scenarios, your code will want to work with this data as if it were a database, but in a strong-typed way. There are a few ways to do this. Basic using As and AsList // Get all and convert to Person var people = AsList<Person>(App.Data.GetStream(\"Person\")); // Get all and convert the first to person - will be null if there is no data var onePerson = As<Person>(App.Data.GetStream(\"Person\")); // Get all, convert, then find the one with the ID - null if no match var person45 = AsList<Person>(App.Data.GetStream(\"Person\")).FirstOrDefault(p => p.Id == 45); // Get one and convert to Person - null if no match; faster var person72 = As<Person>(App.Data.GetStream(\"Person\").List.FirstOrDefault(e => e.EntityId = 72)); This all works, but it's a bit verbose and you will sometimes do too much work, which is not ideal for performance. New using GetAll and GetOne The most common operations will be to get all or get a specific item. This is now much easier: // Get all and convert to Person var people = App.Data.GetAll<Person>(); // Get one and convert using int-id - will be null if not found var person72 = App.Data.GetOne<Person>(72); // Get one and convert using Guid - will be null if not found var personFromGuid = App.Data.GetOne<Person>(Guid.Parse(\"...\")); Good to Know To make the magic work, GetAll(...) and GetOne(...) will use the class name to determine the stream it should retrieve. If the stream does not exist, it means that the Content-Type doesn't exist, and it will throw an error If the stream exists, but the data is empty, it will return an empty list or null, depending on the method used History Introduced in v17.03"
"keywords": "Strong Typed App Data in 2sxc 17+ The App.Data object provides a DataSource to all the data inside the App. In some scenarios, your code will want to work with this data as if it were a database, but in a strong-typed way. There are a few ways to do this. New using GetAll and GetOne The most common operations will be to get all or get a specific item. This is now much easier: // Get all and convert to Person var people = App.Data.GetAll<Person>(); // Get one and convert using int-id - will be null if not found var person72 = App.Data.GetOne<Person>(72); // Get one and convert using Guid - will be null if not found var personFromGuid = App.Data.GetOne<Person>(Guid.Parse(\"...\")); Basic using As and AsList // Get all and convert to Person var people = AsList<Person>(App.Data.GetStream(\"Person\")); // Get all and convert the first to person - will be null if there is no data var onePerson = As<Person>(App.Data.GetStream(\"Person\")); // Get all, convert, then find the one with the ID - null if no match var person45 = AsList<Person>(App.Data.GetStream(\"Person\")).FirstOrDefault(p => p.Id == 45); // Get one and convert to Person - null if no match; faster var person72 = As<Person>(App.Data.GetStream(\"Person\").List.FirstOrDefault(e => e.EntityId = 72)); This all works, but it's a bit verbose and you will sometimes do too much work, which is not ideal for performance. Good to Know To make the magic work, GetAll(...) and GetOne(...) will use the class name to determine the stream it should retrieve. If the stream does not exist, it means that the Content-Type doesn't exist, and it will throw an error If the stream exists, but the data is empty, it will return an empty list or null, depending on the method used History Introduced in v17.03"
},
"net-code/api-typed-strong/content-types.html": {
"href": "net-code/api-typed-strong/content-types.html",
Expand Down
22 changes: 11 additions & 11 deletions docs/net-code/api-typed-strong/app-data-typed.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,6 @@ <h1 id="strong-typed-app-data-in-2sxc-17">Strong Typed App Data in 2sxc 17+</h1>
<p>The <code>App.Data</code> object provides a <strong>DataSource</strong> to all the data inside the App.</p>
<p>In some scenarios, your code will want to work with this data as if it were a database, but in a strong-typed way.</p>
<p>There are a few ways to do this.</p>
<h2 id="basic-using-as-and-aslist">Basic using As and AsList</h2>
<pre><code class="lang-csharp">// Get all and convert to Person
var people = AsList&lt;Person&gt;(App.Data.GetStream(&quot;Person&quot;));
// Get all and convert the first to person - will be null if there is no data
var onePerson = As&lt;Person&gt;(App.Data.GetStream(&quot;Person&quot;));
// Get all, convert, then find the one with the ID - null if no match
var person45 = AsList&lt;Person&gt;(App.Data.GetStream(&quot;Person&quot;)).FirstOrDefault(p =&gt; p.Id == 45);
// Get one and convert to Person - null if no match; faster
var person72 = As&lt;Person&gt;(App.Data.GetStream(&quot;Person&quot;).List.FirstOrDefault(e =&gt; e.EntityId = 72));
</code></pre>
<p>This all works, but it's a bit verbose and you will sometimes do too much work, which is not ideal for performance.</p>
<h2 id="new-using-getall-and-getone">New using GetAll and GetOne</h2>
<p>The most common operations will be to get all or get a specific item.
This is now much easier:</p>
Expand All @@ -134,6 +123,17 @@ <h2 id="new-using-getall-and-getone">New using GetAll and GetOne</h2>
// Get one and convert using Guid - will be null if not found
var personFromGuid = App.Data.GetOne&lt;Person&gt;(Guid.Parse(&quot;...&quot;));
</code></pre>
<h2 id="basic-using-as-and-aslist">Basic using As and AsList</h2>
<pre><code class="lang-csharp">// Get all and convert to Person
var people = AsList&lt;Person&gt;(App.Data.GetStream(&quot;Person&quot;));
// Get all and convert the first to person - will be null if there is no data
var onePerson = As&lt;Person&gt;(App.Data.GetStream(&quot;Person&quot;));
// Get all, convert, then find the one with the ID - null if no match
var person45 = AsList&lt;Person&gt;(App.Data.GetStream(&quot;Person&quot;)).FirstOrDefault(p =&gt; p.Id == 45);
// Get one and convert to Person - null if no match; faster
var person72 = As&lt;Person&gt;(App.Data.GetStream(&quot;Person&quot;).List.FirstOrDefault(e =&gt; e.EntityId = 72));
</code></pre>
<p>This all works, but it's a bit verbose and you will sometimes do too much work, which is not ideal for performance.</p>
<h2 id="good-to-know">Good to Know</h2>
<ul>
<li>To make the magic work, <code>GetAll(...)</code> and <code>GetOne(...)</code> will use the <strong>class name</strong> to determine the stream it should retrieve.</li>
Expand Down

0 comments on commit a627418

Please sign in to comment.