Class ModelFromEntity
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>, IModelSetup<ModelEntityWithLanguagesOption>, ICanBeEntity, IEquatable<ModelFromEntity>
- Inheritance
-
objectModelFromEntity
- Implements
-
IModelSetup<ModelEntityWithLanguagesOption>
- Derived
- Extension Methods
Remarks
This Core implementation has zero public properties, so no public Id, Guid or Title properties.
When serialized or used otherwise it will not include anything which was not added explicitly.
If you want a base class which has these properties ModelFromEntityFull
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 it's risky to use this
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
entityIEntityEntity to wrap
ModelFromEntity(IEntity, string?[])
protected ModelFromEntity(IEntity entity, string?[] languages)
Parameters
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
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
fallbackTValue to provide if nothing was found - required
propertyNamestringThe property name - will be auto-filled by the compiler
Returns
- T
The typed value
Type Parameters
TOptional type, usually auto-detected because of the
fallbackvalue
Get<T>(string, T?)
Get a value from the underlying entity.
protected T? Get<T>(string fieldName, T? fallback)
Parameters
fieldNamestringfield name
fallbackTfallback value
Returns
- T
The value. If the Entity is missing, will return the fallback result.
Type Parameters
Ttype, should only be string, decimal, bool
SetupModel(ModelEntityWithLanguagesOption?)
Add the contents to use for the wrapper. We are not doing this in the constructor, because the object needs to have an empty or DI-compatible constructor.
public bool SetupModel(ModelEntityWithLanguagesOption? source)
Parameters
sourceModelEntityWithLanguagesOption
Returns
- bool
trueif all is ok,falseif not. A typical example would be a wrapper which is setup withnulland it cannot work that way. On the other hand, if a wrapper is ok with a null source, it would returntrue.