Class DynamicEntity
A dynamic entity object - the main object you use when templating things in RazorComponent objects
Note that it will provide many things not listed here, usually things like .Image
, .FirstName
etc. based on your ContentType.
Inheritance
Implements
Namespace: ToSic.Sxc.Data
Assembly: ToSic.Sxc.dll
Syntax
[PublicApi_Stable_ForUseInYourCode]
public class DynamicEntity : DynamicEntityBase, IDynamicMetaObjectProvider, IPropertyLookup, ICanGetByName, IDynamicEntity, IDynamicEntity, IEntityWrapper, IHasDecorators<IEntity>, IMultiWrapper<IEntity>, ICanBeEntity, IDynamicEntityBase, ICanDebug, ISxcDynamicObject, IEquatable<IEntityWrapper>, IList<IDynamicEntity>, ICollection<IDynamicEntity>, IEnumerable<IDynamicEntity>, IList<object>, ICollection<object>, IEnumerable<object>, IEnumerable, IHasMetadata
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
public bool AnyBooleanProperty { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
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
public IEnumerable<DynamicEntity> AnyChildrenProperty { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<DynamicEntity> |
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
public DateTime AnyDateTimeProperty { get; }
Property Value
Type | Description |
---|---|
System.DateTime |
AnyJsonProperty
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 .Gps
or whatever other property your item has.
If the field contains JSON, it will just magically work and return a string
.
If it doesn't exist, it will return null.
Declaration
public string AnyJsonProperty { get; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
Very often you'll want to use the Json as a dynamic object again.
Just pass the result through AsDynamic
and it will work.
Example: var gps = AsDynamic(myThing.Gps); var lat = gps.Lat;
Read more about this in the Dnn JSON Tutorials
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
public string AnyLinkOrFileProperty { get; }
Property Value
Type | Description |
---|---|
System.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
public double AnyNumberProperty { get; }
Property Value
Type | Description |
---|---|
System.Double |
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
public string AnyStringProperty { get; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
Remember to use @Html.Raw(...)
if you want the html to be preserved and not cleaned when placed in the page.
AnyTitleOfAnEntityInTheList
If this DynamicEntity carries a list of items (for example a BlogPost.Tags
which behaves as the first Tag, but also carries all the tags in it)
Then you can also use DynamicCode to directly navigate to a sub-item, like Blogs.Tags.WebDesign
.
Declaration
public IEnumerable<DynamicEntity> AnyTitleOfAnEntityInTheList { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<DynamicEntity> |
Remarks
New in 12.03
Count
Shows how many Entities are available if you use foreach. Will usually return an int
.
Declaration
public object Count { get; }
Property Value
Type | Description |
---|---|
System.Object | Usually an |
Remarks
If the Entity contains a field Count
, that will be returned instead.
EntityGuid
The guid of the underlying entity.
Declaration
public Guid EntityGuid { get; }
Property Value
Type | Description |
---|---|
System.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
public int EntityId { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
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
public object EntityTitle { get; }
Property Value
Type | Description |
---|---|
System.Object | 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. |
EntityType
The type name of the current entity. This provides the nice name like "Person" and not the technical internal StaticName
Declaration
public string EntityType { get; }
Property Value
Type | Description |
---|---|
System.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
public bool IsDemoItem { get; }
Property Value
Type | Description |
---|---|
System.Boolean | True if this is the item configured in the view-settings, false if not. |
Remarks
New in 10.07
IsFake
Declaration
public bool IsFake { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsPublished
Tells us if this data item is published or still draft. Default is true.
Declaration
public bool IsPublished { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Metadata
The type name of the current entity. This provides the nice name like "Person" and not the technical internal StaticName
Declaration
public IDynamicMetadata Metadata { get; }
Property Value
Type | Description |
---|---|
IDynamicMetadata |
Remarks
Added in v13
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
public dynamic Presentation { get; }
Property Value
Type | Description |
---|---|
System.Object | 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
public List<IDynamicEntity> Children(string field = null, string type = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | Optional field filter - would only return items that point to the current item in a specific field name. |
System.String | type | Optional type filter - would only return items of this type. |
Returns
Type | Description |
---|---|
System.Collections.Generic.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
public IDynamicField Field(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name |
Returns
Type | Description |
---|---|
IDynamicField |
Remarks
History: Added in v13.10
GetDraft()
Get the draft item of this item if this is a content-item which is published, and has a draft.
Declaration
public dynamic GetDraft()
Returns
Type | Description |
---|---|
System.Object | 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
public dynamic GetPublished()
Returns
Type | Description |
---|---|
System.Object | Returns a dynamic entity if there is a draft, or null if there is no draft. |
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
public List<IDynamicEntity> Parents(string type = null, string field = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | type | Optional type filter - would only return items of this type. |
System.String | field | Optional field filter - would only return items that point to the current item in a specific field name. |
Returns
Type | Description |
---|---|
System.Collections.Generic.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()