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>, ICanBeEntity, IEquatable<ModelFromEntity>
- Inheritance
-
objectModelFromEntity
- 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
entityIEntityEntity 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
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