Skip to content

Commit 5027d69

Browse files
committed
Updated entity configurations
1 parent 7568240 commit 5027d69

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

src/MADE.Data.EFCore/EntityBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace 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>

src/MADE.Data.EFCore/Extensions/EntityBaseExtensions.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)