Table of Contents

Class ModelOfEntityCore

Namespace
ToSic.Eav.Models
Assembly
ToSic.Eav.Data.dll

Foundation for a class which gets its data from an Entity.

[InternalApi_DoNotUse_MayChangeWithoutNotice]
public abstract record ModelOfEntityCore : IModelSetup<IEntity>, IWrapper<IEntity>, ICanBeEntity, IEquatable<ModelOfEntityCore>
Inheritance
object
ModelOfEntityCore
Implements
Derived
Extension Methods

Remarks

This is used for more type safety - because some internal objects need entities for data-storage, but when programming they should use typed objects to not accidentally access invalid properties.

The Core implementation has zero public properties, so when serialized etc. will not include anything which was not added explicitly.

Constructors

ModelOfEntityCore()

Empty constructor, mainly for factories which must call the setup (otherwise risky to use)

protected ModelOfEntityCore()

ModelOfEntityCore(IEntity)

Standard constructor providing the entity.

protected ModelOfEntityCore(IEntity entity)

Parameters

entity IEntity

Entity to wrap

Properties

Entity

Property to access the underlying entity.

protected IEntity Entity { get; }

Property Value

IEntity

Remarks

Note that many inheriting objects will implement this explicitly, so the property is not visible on the object, unless you first cast it to ICanBeEntity.

Methods

GetThis<T>(T?, string)

Get a value from the underlying entity, whose name matches the property requesting this. So if your C# property is called Birthday it will also get the field Birthday in the entity.

protected T? GetThis<T>(T? fallback, string propertyName = null)

Parameters

fallback T

Value to provide if nothing was found - required

propertyName string

The property name - will be auto-filled by the compiler

Returns

T

The typed value

Type Parameters

T

Optional type, usually auto-detected because of the fallback value

Get<T>(string, T?)

Get a value from the underlying entity.

protected T? Get<T>(string fieldName, T? fallback)

Parameters

fieldName string

field name

fallback T

fallback value

Returns

T

The value. If the Entity is missing, will return the fallback result.

Type Parameters

T

type, should only be string, decimal, bool