Table of Contents

Class ModelFromEntity

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

Foundation for a record which gets its data from an Entity. Completely empty, no public properties.

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

Remarks

This Core implementation has zero public properties, so no public Id, Guid or Title properties. If serialized or use otherwise it will not include anything which was not added explicitly.

This is the record implementation, which is the preferred future way of creating models. To use the class based implementation (for example in DNN code not supporting c# 10), use the ModelFromEntityClassic

Constructors

ModelFromEntity()

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

protected ModelFromEntity()

Remarks

This is the primary constructor used by most inheriting classes.

ModelFromEntity(IEntity)

Standard constructor providing the entity during construction.

protected ModelFromEntity(IEntity entity)

Parameters

entity IEntity

Entity to wrap

Properties

Entity

The underlying entity. It's explicitly not public, so it won't end up in serializations etc. So it's only accessible from within the object (protected).

protected IEntity Entity { get; }

Property Value

IEntity

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