• Basics
  • Abyss
  • Web APIs
  • C# & Razor
  • .net API
  • JS & TS API

    Show / Hide Table of Contents

    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
    System.Object
    System.Dynamic.DynamicObject
    ToSic.Sxc.Data.DynamicEntityBase
    DynamicEntity
    Implements
    System.Dynamic.IDynamicMetaObjectProvider
    IDynamicEntity
    IEntityWrapper
    IHasDecorators<IEntity>
    System.IEquatable<IEntityWrapper>
    System.Collections.Generic.IList<IDynamicEntity>
    System.Collections.Generic.ICollection<IDynamicEntity>
    System.Collections.Generic.IEnumerable<IDynamicEntity>
    System.Collections.Generic.IList<System.Object>
    System.Collections.Generic.ICollection<System.Object>
    System.Collections.Generic.IEnumerable<System.Object>
    System.Collections.IEnumerable
    IHasMetadata
    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 Source

    AnyBooleanProperty

    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
    | Improve this Doc View Source

    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

    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    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

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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

    | Improve this Doc View Source

    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 int but if the Entity contains such a property, then it has the type of that property.

    Remarks

    If the Entity contains a field Count, that will be returned instead.

    | Improve this Doc View Source

    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

    | Improve this Doc View Source

    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

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    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

    | Improve this Doc View Source

    IsFake

    Declaration
    public bool IsFake { get; }
    Property Value
    Type Description
    System.Boolean
    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    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

    | Improve this Doc View Source

    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 Source

    Children(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()

    | Improve this Doc View Source

    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

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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()

    Implements

    System.Dynamic.IDynamicMetaObjectProvider
    IDynamicEntity
    IEntityWrapper
    IHasDecorators<T>
    System.IEquatable<T>
    System.Collections.Generic.IList<T>
    System.Collections.Generic.ICollection<T>
    System.Collections.Generic.IEnumerable<T>
    System.Collections.Generic.IList<T>
    System.Collections.Generic.ICollection<T>
    System.Collections.Generic.IEnumerable<T>
    System.Collections.IEnumerable
    IHasMetadata
    • Improve this Doc
    • View Source
    Back to top Generated by DocFX