Skip to content

Entities

Furkan Güngör edited this page Nov 28, 2021 · 1 revision

Summary

It supports all entities of EasyRepository class type. However, EasyRepository includes a base entity to facilitate operations.

With the EasyBaseEntity class;

  • PrimaryKey
  • CreationDate
  • DeletionDate
  • IsDeleted
  • ModificationDate includes fields.

If you create your models with EasyBaseEntity, the above information is automatically set in Create, Update and Delete operations. For entities derived with EasyBaseEntity, the SoftDelete feature is additionally available.

Do not worry. To use the EasyRepository library, its models do not have to derive from the EasyBaseEntity class. EasyRepository works seamlessly for your own assets as well.

EasyBaseEntity

/// <summary>
/// This abstraction implemented base properties for entities
/// </summary>
/// <typeparam name="TPrimaryKey">
/// Primary Key type of the entity
/// </typeparam>
public abstract class EasyBaseEntity<TPrimaryKey> : IEasyEntity<TPrimaryKey>, IEasyCreateDateEntity, IEasyUpdateDateEntity, IEasySoftDeleteEntity
{
    /// <summary>
    /// Creation Date <see cref="{DateTime}"/>
    /// </summary>
    public virtual DateTime CreationDate { get; set; }
    /// <summary>
    /// Primary Key <see cref="{TPrimaryKey}"/>
    /// </summary>
    public virtual TPrimaryKey Id { get; set; }
    /// <summary>
    /// Modification Date <see cref="{DateTime}"/>
    /// </summary>
    public virtual DateTime? ModificationDate { get; set; }
    /// <summary>
    /// Deletion Date <see cref="{DateTime}"/>
    /// </summary>
    public virtual DateTime? DeletionDate { get; set; }
    /// <summary>
    /// Is Deleted <see cref="{Boolean}"/>
    /// </summary>
    public virtual bool IsDeleted { get; set; }
}

An example entity with EasyBaseEntity

public class Author : EasyBaseEntity<Guid>
{
    public string Name { get; set; }
    public string Surname { get; set; }
    public virtual ICollection<Book> Books { get; set; }
}
public class Book : EasyBaseEntity<Guid>
{
    public string Title { get; set; }
    public Guid AuthorId { get; set; }
    public int TotalPage { get; set; }
    public virtual Author Author { get; set; }
}
Clone this wiki locally