Class ModelOfEntityCore
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
-
objectModelOfEntityCore
- 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
entityIEntityEntity to wrap
Properties
Entity
Property to access the underlying entity.
protected IEntity Entity { get; }
Property Value
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
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