Interface IDynamicEntity
This is a wrapper for IEntity objects. It provides nicer access to underlying properties and automatically handles things like multi-language etc. The underlying IEntity IEntity is in the Entity property.
Normally you will use it without caring about these internals.
Please check @HowTo.DynamicCode.DynamicEntity
Namespace: ToSic.Sxc.Data
Assembly: ToSic.Sxc.dll
Syntax
[PublicApi_Stable_ForUseInYourCode]
public interface IDynamicEntity : IHasDecorators<IEntity>, ICanDebug
Properties
| Improve this Doc View SourceAnyBooleanProperty
A Dynamic Entity always contains an item of your data - a book, person, blog-post or a piece of content.
Since the object is dynamic, you can just use .IsFemale
or whatever other property your item has.
If it's a true/false, it will just magically work and return a bool
. If it doesn't exist, it will return null.
Declaration
bool AnyBooleanProperty { get; }
Property Value
Type | Description |
---|---|
bool |
AnyChildrenProperty
A Dynamic Entity always contains an item of your data - a book, person, blog-post or a piece of content.
Since the object is dynamic, you can just use .Tags
or whatever other property your item has.
If it's contains relationships, it will just magically work and return a list of further DynamicEntity
objects.
If it doesn't exist, it will return null.
Declaration
IEnumerable<IDynamicEntity> AnyChildrenProperty { get; }
Property Value
Type | Description |
---|---|
IEnumerable<IDynamicEntity> |
Remarks
Very often you'll want to use LINQ to further sort or query these items.
But the Razor compiler cannot know that it got a list, so using .Any()
or similar fails.
To fix this, put an AsList
around it - a bit like AsList(myThing.Tags)
.
Sometimes you'll also need to help a bit more with AsList(myThings.Tags as object)
.
Now you can do things like var tags = AsList(myThings.Tags as object); if (myTags.Any()) {...}
Read more about this in the Dnn LINQ Tutorials
AnyDateTimeProperty
A Dynamic Entity always contains an item of your data - a book, person, blog-post or a piece of content.
Since the object is dynamic, you can just use .Birthday
or whatever other property your item has.
If it's a date/time, it will just magically work and return a DateTime
. If it doesn't exist, it will return null.
Declaration
DateTime AnyDateTimeProperty { get; }
Property Value
Type | Description |
---|---|
DateTime |
AnyLinkOrFileProperty
A Dynamic Entity always contains an item of your data - a book, person, blog-post or a piece of content.
Since the object is dynamic, you can just use .Image
or whatever other property your item has.
If it's a link, it will just magically work and return a string
. If it doesn't exist, it will return null.
Declaration
string AnyLinkOrFileProperty { get; }
Property Value
Type | Description |
---|---|
string |
Remarks
Note that many internal references in the CMS use file:2742
or similar. This will automatically be resolved to the real
link which your output needs.
AnyNumberProperty
A Dynamic Entity always contains an item of your data - a book, person, blog-post or a piece of content.
Since the object is dynamic, you can just use .Length
or whatever other property your item has.
If it's a number, it will just magically work and return a double
. If it doesn't exist, it will return null.
Declaration
decimal AnyNumberProperty { get; }
Property Value
Type | Description |
---|---|
decimal |
AnyStringProperty
A Dynamic Entity always contains an item of your data - a book, person, blog-post or a piece of content.
Since the object is dynamic, you can just use .FirstName
or whatever other property your item has.
If it's a string, it will just magically work. If it doesn't exist, it will return null.
Declaration
string AnyStringProperty { get; }
Property Value
Type | Description |
---|---|
string |
Remarks
Remember to use @Html.Raw(...)
if you want the html to be preserved and not cleaned when placed in the page.
EntityGuid
The guid of the underlying entity.
Declaration
Guid EntityGuid { get; }
Property Value
Type | Description |
---|---|
Guid |
Remarks
If the entity doesn't exist, it will return an empty guid
EntityId
The ID of the underlying entity. Use it for edit-functionality or just to have a unique number for this item.
Declaration
int EntityId { get; }
Property Value
Type | Description |
---|---|
int |
Remarks
If the entity doesn't exist, it will return 0
EntityTitle
The title of this item. This is always available no matter what the underlying field for the title is.
Declaration
string EntityTitle { get; }
Property Value
Type | Description |
---|---|
string | The title of the underlying entity. In rare cases where no title-field is known, it can be null. It can also be null if there is no underlying entity. |
Remarks
This returns a string which is usually what's expected. In previous versions (before v15) 2sxc it returned an object.
EntityType
The type name of the current entity. This provides the nice name like "Person" and not the technical internal StaticName
Declaration
string EntityType { get; }
Property Value
Type | Description |
---|---|
string |
IsDemoItem
Many templates show demo data.
If the template code must know if it's the demo item or
real data, use .IsDemoItem
.
Declaration
bool IsDemoItem { get; }
Property Value
Type | Description |
---|---|
bool | True if this is the item configured in the view-settings, false if not. |
Remarks
New in 10.07 on IDynamicEntity, new in 16.02 on ITypedEntity
IsPublished
Tells us if this data item is published or still draft. Default is true.
Declaration
bool IsPublished { get; }
Property Value
Type | Description |
---|---|
bool |
Metadata
The type name of the current entity. This provides the nice name like "Person" and not the technical internal StaticName
Declaration
IMetadata Metadata { get; }
Property Value
Type | Description |
---|---|
IMetadata |
Remarks
- Added in v13
- Changed type name to
IMetadata
fromIDynamicMetadata
in 16.02; same type, different type name
Presentation
Contains presentation settings for an item - if they exist.
This is a functionality of the CMS, where an instance of an item can be configured to show in a specific way.
Normally it's used when something like an address has various show-settings (like how the map should visualize this address).
The presentation-info is therefor not-null IF
- the content belongs to this module instance
- the view-configuration of this module is configured to have presentation items
- there is either a default presentation configured in the view, or the user has manually edited the presentation settings
Declaration
dynamic Presentation { get; }
Property Value
Type | Description |
---|---|
dynamic | An IDynamicEntity with the presentation item (or the demo-presentation), otherwise null. |
Methods
| Improve this Doc View SourceChildren(string, string)
A dynamic list of sub-items. Important for LINQ style querying or just
working with various lists. Note that for getting child items of this item you
can just use the properties, like content.Authors.
But using Children("Authors", typeName) gives you the ability to restrict to a type.
Please check the tutorials on 2sxc.org/dnn-tutorials/ for more info.
Declaration
List<IDynamicEntity> Children(string field = null, string type = null)
Parameters
Type | Name | Description |
---|---|---|
string | field | Optional field filter - would only return items that point to the current item in a specific field name. |
string | type | Optional type filter - would only return items of this type. |
Returns
Type | Description |
---|---|
List<IDynamicEntity> | A list of all items pointing here (filtered), converted to DynamicEntity for convenience. |
Remarks
New in 10.21.00 - note also that the parameter-order is reversed to the Parents()
Field(string)
Get a Field-object of a property of this entity, to use with services like the IImageService which also need more information like the metadata.
Declaration
IField Field(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name |
Returns
Type | Description |
---|---|
IField |
Remarks
History: Added in v13.10
Get(string)
Declaration
dynamic Get(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name |
Returns
Type | Description |
---|---|
dynamic |
Get(string, string, string, bool, bool?)
Get a property using the string name. Only needed in special situations, as most cases can use the object.name directly
Declaration
dynamic Get(string name, string noParamOrder = "Params must be named (https://go.2sxc.org/named-params)", string language = null, bool convertLinks = true, bool? debug = null)
Parameters
Type | Name | Description |
---|---|---|
string | name | the property name like |
string | noParamOrder | |
string | language | Optional language code - like "de-ch" to prioritize that language |
bool | convertLinks | Optionally turn off if links like file:72 are looked up to a real link. Default is true. |
bool? | debug | Set true to see more details in Insights how the value was retrieved. |
Returns
Type | Description |
---|---|
dynamic | a dynamically typed result, can be string, bool, etc. |
GetDraft()
Get the draft item of this item if this is a content-item which is published, and has a draft.
Declaration
dynamic GetDraft()
Returns
Type | Description |
---|---|
dynamic | Returns a dynamic entity if there is a draft, or null if there is no draft. |
GetPublished()
Get the published item of this item if this is a content-item which is draft, and has a published.
Declaration
dynamic GetPublished()
Returns
Type | Description |
---|---|
dynamic | Returns a dynamic entity if there is a draft, or null if there is no draft. |
Get<TValue>(string)
Get a value using the name - and cast it to the expected strong type. For example to get an int even though it's stored as decimal.
Declaration
TValue Get<TValue>(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | the property name like |
Returns
Type | Description |
---|---|
TValue | The typed value, or the |
Type Parameters
Name | Description |
---|---|
TValue | The expected type, like |
Remarks
Added in v15
Get<TValue>(string, string, TValue)
Get a value using the name - and cast it to the expected strong type. For example to get an int even though it's stored as decimal.
Since the parameter fallback
determines the type TValue
you can just write this like
`Content.Get("Title", fallback: "no title")
Declaration
TValue Get<TValue>(string name, string noParamOrder = "Params must be named (https://go.2sxc.org/named-params)", TValue fallback = default)
Parameters
Type | Name | Description |
---|---|---|
string | name | the property name like |
string | noParamOrder | |
TValue | fallback | the fallback value to provide if not found |
Returns
Type | Description |
---|---|
TValue | The typed value, or the |
Type Parameters
Name | Description |
---|---|
TValue | The expected type, like |
Remarks
Added in v15
Html(string, string, object, bool?, object, bool)
Show a field in the expected / best possible way. As of now it's meant for WYSIWYG fields with Very-Rich Text. See DynamicEntity / TypedItem .Html(...) Method new v16.01
Declaration
IHtmlTag Html(string name, string noParamOrder = "Params must be named (https://go.2sxc.org/named-params)", object container = null, bool? toolbar = null, object imageSettings = null, bool debug = false)
Parameters
Type | Name | Description |
---|---|---|
string | name | the field name |
string | noParamOrder | |
object | container | A wrapper tag for the result.
It's either a RazorBlade tag such as |
bool? | toolbar | Override default toolbar behavior on this field. See docs |
object | imageSettings | Settings for resizing. Default is |
bool | debug | Activate debug visualization to better see alignments and such. |
Returns
Type | Description |
---|---|
IHtmlTag |
Remarks
- Added in 2sxc 16.01
- Only works on Razor files inheriting from Hybrid14 or newer
Parents(string, string)
A dynamic list of entities which point to this item. Important for LINQ style querying or just
working with various lists. Note that for getting child items of this item you
can just use the properties, like content.Authors.
Please check the tutorials on 2sxc.org/dnn-tutorials/ for more info.
Declaration
List<IDynamicEntity> Parents(string type = null, string field = null)
Parameters
Type | Name | Description |
---|---|---|
string | type | Optional type filter - would only return items of this type. |
string | field | Optional field filter - would only return items that point to the current item in a specific field name. |
Returns
Type | Description |
---|---|
List<IDynamicEntity> | A list of all items pointing here (filtered), converted to DynamicEntity for convenience. |
Remarks
New in 9.42 - note also that the parameter-order is reversed to the Children()