Class ModelFromItem
BETA / WIP: Base class for plain data models and can be used in Razor Components. It wraps an ITypedItem and provides a simple way to access the data.
[InternalApi_DoNotUse_MayChangeWithoutNotice("Still beta, name may change to DataModelWithItem or something")]
public abstract class ModelFromItem : ICanWrap<ITypedItem>, ICanWrapData, IMultiWrapper<IEntity>, IEquatable<ITypedItem>
  - Inheritance
 - 
      objectModelFromItem
 
- Implements
 
- Derived
 
Examples
Usage ca. like this:
- A custom data model in 
AppCode.Datawhich inherits from this class (usually generated by 2sxc Copilot) - Razor code which uses it to convert typed items into this custom data model
 
Example trivial custom plain data model:
namespace AppCode.Data
{
  class MyPerson : DataModelOfItem
  {
    public int Id => _item.Id;
    public string Name => _item.String("Name");
  }
}
Example usage in Razor:
@inherits Custom.Hybrid.RazorTyped
@using AppCode.Data
@{
  var person = As<MyPerson>(MyItem);
}
<span>@person.Name</span>
  Remarks
This is much lighter than the CustomItem which also wraps data, as it doesn't have any predefined properties and doesn't have the ITypedItem APIs.
History
- Released in v19.01 (BETA)
 
Properties
_item
The underlying item - for inheriting classes to access.
protected ITypedItem _item { get; }
  Property Value
Remarks
- this property is protected, not public, as it should only be used internally.
 - this also prevents it from being serialized in JSON, which is good.
 - it uses an unusual name 
_itemto avoid naming conflicts with properties generated in inheriting classes. 
Methods
AsList<T>(object, NoParamOrder, bool)
Convert a list of Entities or TypedItems into a strongly typed list.
Typically, the type will be from your AppCode.Data.
protected IEnumerable<T>? AsList<T>(object source, NoParamOrder protector = default, bool nullIfNull = false) where T : class, ICanWrapData
  Parameters
sourceobjectprotectorNoParamOrdernullIfNullbool
Returns
- IEnumerable<T>
 
Type Parameters
T
As<T>(object)
Convert an Entity or TypedItem into a strongly typed object.
Typically, the type will be from your AppCode.Data.
protected T? As<T>(object item) where T : class, ICanWrapData
  Parameters
itemobject
Returns
- T
 
Type Parameters
T
Equals(object?)
Ensure that the equality check is done correctly. If two objects wrap the same item, they will be considered equal.
public override bool Equals(object? b)
  Parameters
bobject
Returns
ToString()
Override ToString to give more information about the current object
public override string ToString()
  Returns
Operators
operator ==(ModelFromItem, ModelFromItem)
Ensure that the equality check is done correctly. If two objects wrap the same item, they will be considered equal.
public static bool operator ==(ModelFromItem a, ModelFromItem b)
  Parameters
aModelFromItemfirst item to compare
bModelFromItemsecond item to compare
Returns
- bool
 true, if both wrappers are the same type and wrap the same entity
operator !=(ModelFromItem, ModelFromItem)
Ensure that the equality check is done correctly. If two objects wrap the same item, they will be considered equal.
public static bool operator !=(ModelFromItem a, ModelFromItem b)
  Parameters
aModelFromItemfirst item to compare
bModelFromItemsecond item to compare
Returns
- bool
 false, if both wrappers are the same type and wrap the same entity