Neatoo EntityBase is the main component of Neatoo. It provides the bindable properties, triggers rules on property change and bindable meta properties. It also defines the Factory Methods for persisting to the database.

This is a brief overview of EntityBase using the Person entity. More in-depth pages are in the works for each feature.

Class Declaration

internal partial class Person : EntityBase<Person>, IPerson
  • Entities inherit from Neatoo.EntityBase<T> defining themselves as T
  • Partial is required for Neatoo to generate property definitions

Constructor

    public Person(IEntityBaseServices<Person> editBaseServices,
                  IUniqueNameRule uniqueNameRule) : base(editBaseServices)
    {
        RuleManager.AddRule(uniqueNameRule);
    }
  • Depedency Injection using Microsoft.Extension.DependencyInjection is fully supported
  • The base constructor requires IEntityBaseServices for Neatoo Framework constructs
  • Rules are injected and added to the RuleManager

Properties

    [DisplayName("First Name*")]
    [Required(ErrorMessage = "First Name is required")]
    public partial string? FirstName { get; set; }

    [DisplayName("Last Name*")]
    [Required(ErrorMessage = "Last Name is required")]
    public partial string? LastName { get; set; }
  • Partial properties are required as their full definition is a method call
  • Required Attribute is supported. (More to come)

Property Meta Properties

  • Each property is a class with bindable meta properties IsBusy, IsValid and IsModified.
  • These property classes are accessed thru EntityBase.PropertyManager or the EntityBase indexer (ex “MyEntity[nameof(FirstName)]”)

Bindable Meta Properties

IsValid

If a Rule returns a message for a property the Entity and it’s Parent Entities are InValid=true.

IsBusy

Async Rules are executing

IsNew

A Factory Create was used to instantiate the Entity. On Save the Factory Update will be called.

IsModified

The Entity or a Child Entity has a modified property or IsNew=true.

IsDelete

The Entity has been marked for Deletion. On Save the Factory Delete will be called.

IsSelfXYZ

Each Meta Property has a corresponding IsSelf. This excludes Child Enties.

Property Message

  • Each Entity property has a list of messages
  • If a property has a message the property is InValid=false, the Entity is IsValid=false and Parent Entities are IsValid=false
  • EntityBase.PropertyMessages is the full list of property messages

Parent Property

If an EntityBase (“child”) is assigned to the property of another EntityBase (“parent”) then child.Parent will be automatically set i.e. child.Parent = parent. Only the Aggregate Root should have Parent = null.

Factory Methods

    [Create]
    public void Create([Service] IPersonPhoneList PersonPhoneList) {}

    [Remote]
    [Fetch]
    public async Task<bool> Fetch([Service] IPersonDbContext personContext,
                                    [Service] IPersonPhoneListFactory PersonPhoneListFactory) {}

    [Remote]
    [Insert]
    public async Task<PersonEntity?> Insert([Service] IPersonDbContext personContext,
                                    [Service] IPersonPhoneListFactory PersonPhoneListFactory) {}

    [Remote]
    [Update]
    public async Task<PersonEntity?> Update([Service] IPersonDbContext personContext,
                                    [Service] IPersonPhoneListFactory PersonPhoneListFactory) {}

    [Remote]
    [Delete]
    public async Task Delete([Service] IPersonDbContext personContext) {}

Events

Events propagate up thru the Aggregate. An Entity can see all of it’s Child Entity events using EntityBase by overidding ChildNeatooPropertyChanged.

The breadcrumbs of the properties is available in the event args NeatooPropertyChangedEventArgs

Entity Lists

A corresponding EntityList provides a list of Entities while supporting all of the EntityBase Aggregate Entity features.

  • When an item is removed from an EntityList it is marked IsDeleted=true and added to EntityList.DeletedList. Entities within EntityList.DeletedList need to be handled in the Insert/Update/Delete Factory Methods. Ex PersonPhoneList.Update.
  • The value of the Parent property of EntityBases within the list will be the parent of the list not the list itself.
    • Ex. PersonPhone.Parent = Person. NOT PersonPhone.Parent = PersonPhoneList