Skip to content

Commit 6ae92e3

Browse files
authored
Merge pull request #168 from pedrolucasmr/main
Add IEntityBase interface and update concrete class
2 parents add87aa + ea719b6 commit 6ae92e3

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

src/MADE.Data.EFCore/EntityBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace MADE.Data.EFCore
55
/// <summary>
66
/// Defines a base definition for an entity.
77
/// </summary>
8-
public abstract class EntityBase
8+
public abstract class EntityBase : IEntityBase
99
{
1010
/// <summary>
1111
/// Gets or sets the identifier of the entity.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ public static void SetEntityDates(this DbContext context)
6060
IEnumerable<EntityEntry> entries = context.ChangeTracker
6161
.Entries()
6262
.Where(
63-
entry => entry.Entity is EntityBase &&
63+
entry => entry.Entity is IEntityBase &&
6464
(entry.State == EntityState.Added || entry.State == EntityState.Modified));
6565

6666
DateTime now = DateTime.UtcNow;
6767

6868
foreach (EntityEntry entry in entries)
6969
{
70-
var entity = (EntityBase)entry.Entity;
70+
var entity = (IEntityBase)entry.Entity;
7171
entity.UpdatedDate = now;
7272

7373
if (entry.State == EntityState.Added && entity.CreatedDate == DateTime.MinValue)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace MADE.Data.EFCore
2+
{
3+
using System;
4+
5+
/// <summary>
6+
/// Defines a base definition for an entity.
7+
/// </summary>
8+
public interface IEntityBase
9+
{
10+
/// <summary>
11+
/// Gets or sets the identifier of the entity.
12+
/// </summary>
13+
Guid Id { get; set; }
14+
15+
/// <summary>
16+
/// Gets or sets the date of the entity's creation.
17+
/// </summary>
18+
DateTime CreatedDate { get; set; }
19+
20+
/// <summary>
21+
/// Gets or sets the date of the entity's last update.
22+
/// </summary>
23+
DateTime? UpdatedDate { get; set; }
24+
25+
}
26+
}

0 commit comments

Comments
 (0)