mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
parent
b7c0280cc9
commit
fc90f71f5e
3 changed files with 9 additions and 13 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using FilterLists.Data.Models.Implementations;
|
||||
using FilterLists.Data.Models.Contracts;
|
||||
using FilterLists.Data.Models.Implementations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FilterLists.Data.Contexts
|
||||
|
|
@ -11,5 +12,12 @@ public FilterListsDbContext(DbContextOptions options)
|
|||
}
|
||||
|
||||
public DbSet<FilterList> FilterList { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<IBaseEntity>()
|
||||
.Property(b => b.CreatedDateUtc)
|
||||
.HasDefaultValueSql("CURRENT_TIMESTAMP");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using FilterLists.Data.Models.Contracts;
|
||||
|
|
@ -14,12 +13,9 @@ public abstract class BaseEntity : IBaseEntity
|
|||
[JsonIgnore]
|
||||
public long Id { get; set; }
|
||||
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
[DefaultValue("CURRENT_TIMESTAMP")]
|
||||
[JsonIgnore]
|
||||
public DateTime CreatedDateUtc { get; set; }
|
||||
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
|
||||
[JsonIgnore]
|
||||
public DateTime? ModifiedDateUtc { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
--TODO: Possibly convert to stored procedure
|
||||
ALTER TABLE
|
||||
filterlistsdata.FilterList MODIFY COLUMN CreatedDateUtc DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL;
|
||||
ALTER TABLE
|
||||
filterlistsdata.FilterList MODIFY COLUMN ModifiedDateUtc DATETIME DEFAULT NULL;
|
||||
ON
|
||||
UPDATE
|
||||
CURRENT_TIMESTAMP;
|
||||
Loading…
Reference in a new issue