File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ namespace MADE . Data . EFCore
2+ {
3+ using System ;
4+
5+ /// <summary>
6+ /// Defines a base definition for an entity.
7+ /// </summary>
8+ public abstract class EntityBase
9+ {
10+ /// <summary>
11+ /// Gets or sets the identifier of the entity.
12+ /// </summary>
13+ public Guid Id { get ; set ; }
14+
15+ /// <summary>
16+ /// Gets or sets the date of the entity's creation.
17+ /// </summary>
18+ public virtual DateTime CreatedDate { get ; set ; } = DateTime . UtcNow ;
19+
20+ /// <summary>
21+ /// Gets or sets the date of the entity's last update.
22+ /// </summary>
23+ public virtual DateTime ? UpdatedDate { get ; set ; } = DateTime . UtcNow ;
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ namespace MADE . Data . EFCore . Extensions
2+ {
3+ using MADE . Data . EFCore . Converters ;
4+ using Microsoft . EntityFrameworkCore . Metadata . Builders ;
5+
6+ /// <summary>
7+ /// Defines a collection of extensions for the <see cref="EntityBase"/> type.
8+ /// </summary>
9+ public static class EntityBaseExtensions
10+ {
11+ /// <summary>
12+ /// Configures the created and updated date properties of an <typeparamref name="TEntity">entity</typeparamref> as UTC.
13+ /// </summary>
14+ /// <typeparam name="TEntity">The type of entity to configure.</typeparam>
15+ /// <param name="builder">The entity type builder associated with the entity.</param>
16+ /// <returns>The entity type builder.</returns>
17+ public static EntityTypeBuilder < TEntity > ConfigureDateProperties < TEntity > ( this EntityTypeBuilder < TEntity > builder )
18+ where TEntity : EntityBase
19+ {
20+ builder . Property ( x => x . CreatedDate ) . IsUtc ( ) ;
21+ builder . Property ( x => x . UpdatedDate ) . IsUtc ( ) ;
22+ return builder ;
23+ }
24+ }
25+ }
You can’t perform that action at this time.
0 commit comments