File tree Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ namespace MADE.Data.EFCore
5
5
/// <summary>
6
6
/// Defines a base definition for an entity.
7
7
/// </summary>
8
- public abstract class EntityBase
8
+ public abstract class EntityBase : IEntityBase
9
9
{
10
10
/// <summary>
11
11
/// Gets or sets the identifier of the entity.
Original file line number Diff line number Diff line change @@ -60,14 +60,14 @@ public static void SetEntityDates(this DbContext context)
60
60
IEnumerable < EntityEntry > entries = context . ChangeTracker
61
61
. Entries ( )
62
62
. Where (
63
- entry => entry . Entity is EntityBase &&
63
+ entry => entry . Entity is IEntityBase &&
64
64
( entry . State == EntityState . Added || entry . State == EntityState . Modified ) ) ;
65
65
66
66
DateTime now = DateTime . UtcNow ;
67
67
68
68
foreach ( EntityEntry entry in entries )
69
69
{
70
- var entity = ( EntityBase ) entry . Entity ;
70
+ var entity = ( IEntityBase ) entry . Entity ;
71
71
entity . UpdatedDate = now ;
72
72
73
73
if ( entry . State == EntityState . Added && entity . CreatedDate == DateTime . MinValue )
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 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
+ }
You can’t perform that action at this time.
0 commit comments