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

    Show / Hide Table of Contents

    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

    Inherited Members
    IHasDecorators<IEntity>.Decorators
    ICanDebug.Debug
    Namespace: ToSic.Sxc.Data
    Assembly: ToSic.Sxc.dll
    Syntax
    [PublicApi_Stable_ForUseInYourCode]
    public interface IDynamicEntity : IDynamicEntity, IEntityWrapper, IHasDecorators<IEntity>, IMultiWrapper<IEntity>, ICanBeEntity, IDynamicEntityBase, ISxcDynamicObject, ICanDebug

    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
    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
    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
    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
    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
    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
    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
    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
    IEnumerable<DynamicEntity> AnyTitleOfAnEntityInTheList { get; }
    Property Value
    Type Description
    System.Collections.Generic.IEnumerable<DynamicEntity>
    Remarks

    New in 12.03

    | Improve this Doc View Source

    Entity

    The underlying entity which provides all the data for the DynamicEntity

    Declaration
    IEntity Entity { get; }
    Property Value
    Type Description
    IEntity

    An Entity object.

    | Improve this Doc View Source

    EntityGuid

    The guid of the underlying entity.

    Declaration
    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
    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
    string EntityTitle { get; }
    Property Value
    Type Description
    System.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.

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

    IsPublished

    Tells us if this data item is published or still draft. Default is true.

    Declaration
    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
    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
    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
    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
    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

    Get(String)

    Get a value of the entity. Usually you will prefer the quick access like @content.FirstName - which will give you the same things as content.Get("FirstName"). There are two cases to use this:

    • when you dynamically assemble the field name in your code, like when using App.Resources or similar use cases.
    • to access a field which has a conflicting name with this object, like Get("Parents")
    Declaration
    dynamic Get(string name)
    Parameters
    Type Name Description
    System.String name
    Returns
    Type Description
    System.Object

    An object which can be either a string, number, boolean or List<IDynamicEntity>, depending on the field type. Will return null if the field was not found.

    | Improve this Doc View Source

    Get(String, String, String, Boolean, Nullable<Boolean>)

    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://r.2sxc.org/named-params)", string language = null, bool convertLinks = true, bool? debug = default(bool? ))
    Parameters
    Type Name Description
    System.String name

    the property name like Image - or path like Author.Name (new v15)

    System.String noParamOrder

    see Convention: Named Parameters

    System.String language

    Optional language code - like "de-ch" to prioritize that language

    System.Boolean convertLinks

    Optionally turn off if links like file:72 are looked up to a real link. Default is true.

    System.Nullable<System.Boolean> debug

    Set true to see more details in Insights how the value was retrieved.

    Returns
    Type Description
    System.Object

    a dynamically typed result, can be string, bool, etc.

    | Improve this Doc View Source

    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
    System.String name

    the property name like Image - or path like Author.Name (new v15)

    Returns
    Type Description
    TValue

    The typed value, or the default like null or 0 if casting isn't possible.

    Type Parameters
    Name Description
    TValue

    The expected type, like string, int, etc.

    Remarks

    Added in v15

    | Improve this Doc View Source

    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://r.2sxc.org/named-params)", TValue fallback = null)
    Parameters
    Type Name Description
    System.String name

    the property name like Image - or path like Author.Name (new v15)

    System.String noParamOrder

    see Convention: Named Parameters

    TValue fallback

    the fallback value to provide if not found

    Returns
    Type Description
    TValue

    The typed value, or the default like null or 0 if casting isn't possible.

    Type Parameters
    Name Description
    TValue

    The expected type, like string, int, etc. Note that you don't need to specify it, if you specify the fallback property.

    Remarks

    Added in v15

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

    • Improve this Doc
    • View Source
    Back to top Generated by DocFX