File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11namespace MADE . Data . EFCore
22{
33 using System ;
4+ using System . ComponentModel . DataAnnotations . Schema ;
45
56 /// <summary>
67 /// Defines a base definition for an entity.
@@ -10,6 +11,7 @@ public abstract class EntityBase : IEntityBase
1011 /// <summary>
1112 /// Gets or sets the identifier of the entity.
1213 /// </summary>
14+ [ DatabaseGenerated ( DatabaseGeneratedOption . Identity ) ]
1315 public Guid Id { get ; set ; }
1416
1517 /// <summary>
Original file line number Diff line number Diff line change @@ -8,18 +8,33 @@ namespace MADE.Data.EFCore.Extensions
88 /// </summary>
99 public static class EntityBaseExtensions
1010 {
11+ /// <summary>
12+ /// Configures the default properties of an <typeparamref name="TEntity">entity</typeparamref>.
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 > Configure < TEntity > ( this EntityTypeBuilder < TEntity > builder )
18+ where TEntity : class , IEntityBase
19+ {
20+ builder . HasKey ( e => e . Id ) ;
21+ builder . ConfigureDateProperties ( ) ;
22+ return builder ;
23+ }
24+
1125 /// <summary>
1226 /// Configures the created and updated date properties of an <typeparamref name="TEntity">entity</typeparamref> as UTC.
1327 /// </summary>
1428 /// <typeparam name="TEntity">The type of entity to configure.</typeparam>
1529 /// <param name="builder">The entity type builder associated with the entity.</param>
1630 /// <returns>The entity type builder.</returns>
17- public static EntityTypeBuilder < TEntity > ConfigureDateProperties < TEntity > ( this EntityTypeBuilder < TEntity > builder )
18- where TEntity : EntityBase
31+ public static EntityTypeBuilder < TEntity > ConfigureDateProperties < TEntity > (
32+ this EntityTypeBuilder < TEntity > builder )
33+ where TEntity : class , IEntityBase
1934 {
2035 builder . Property ( x => x . CreatedDate ) . IsUtc ( ) ;
2136 builder . Property ( x => x . UpdatedDate ) . IsUtc ( ) ;
2237 return builder ;
2338 }
2439 }
25- }
40+ }
You can’t perform that action at this time.
0 commit comments