From 940f0b8327d0ac30d804d37dffa3a7a28cd91f99 Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Mon, 10 Apr 2017 08:18:10 -0500 Subject: [PATCH] annotation updates --- ...0410130859_SetDefaultDateValue.Designer.cs | 64 +++++++++++++++++++ .../20170410130859_SetDefaultDateValue.cs | 19 ++++++ api/FilterLists.Models/BaseEntity.cs | 4 ++ 3 files changed, 87 insertions(+) create mode 100644 api/FilterLists.Data/Migrations/20170410130859_SetDefaultDateValue.Designer.cs create mode 100644 api/FilterLists.Data/Migrations/20170410130859_SetDefaultDateValue.cs diff --git a/api/FilterLists.Data/Migrations/20170410130859_SetDefaultDateValue.Designer.cs b/api/FilterLists.Data/Migrations/20170410130859_SetDefaultDateValue.Designer.cs new file mode 100644 index 000000000..a93ddf059 --- /dev/null +++ b/api/FilterLists.Data/Migrations/20170410130859_SetDefaultDateValue.Designer.cs @@ -0,0 +1,64 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using FilterLists.Data.Contexts; + +namespace FilterLists.Data.Migrations +{ + [DbContext(typeof(FilterListsDbContext))] + [Migration("20170410130859_SetDefaultDateValue")] + partial class SetDefaultDateValue + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.1.1"); + + modelBuilder.Entity("FilterLists.Models.List", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedDateUtc") + .ValueGeneratedOnAdd(); + + b.Property("Description") + .HasMaxLength(512); + + b.Property("DescriptionSourceUrl") + .HasMaxLength(2083); + + b.Property("DonateUrl") + .HasMaxLength(2083); + + b.Property("Email") + .HasMaxLength(254); + + b.Property("ForumUrl") + .HasMaxLength(2083); + + b.Property("HomeUrl") + .HasMaxLength(2083); + + b.Property("IssuesUrl") + .HasMaxLength(2083); + + b.Property("ModifiedDateUtc") + .ValueGeneratedOnAddOrUpdate(); + + b.Property("Name") + .HasMaxLength(64); + + b.Property("ViewUrl") + .IsRequired() + .HasMaxLength(2083); + + b.HasKey("Id"); + + b.ToTable("List"); + }); + } + } +} diff --git a/api/FilterLists.Data/Migrations/20170410130859_SetDefaultDateValue.cs b/api/FilterLists.Data/Migrations/20170410130859_SetDefaultDateValue.cs new file mode 100644 index 000000000..e73ebd45a --- /dev/null +++ b/api/FilterLists.Data/Migrations/20170410130859_SetDefaultDateValue.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace FilterLists.Data.Migrations +{ + public partial class SetDefaultDateValue : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/api/FilterLists.Models/BaseEntity.cs b/api/FilterLists.Models/BaseEntity.cs index fd5b0cec1..0e5af86f4 100644 --- a/api/FilterLists.Models/BaseEntity.cs +++ b/api/FilterLists.Models/BaseEntity.cs @@ -1,6 +1,7 @@ //https://code.msdn.microsoft.com/Generic-Repository-Pattern-f133bca4/sourcecode?fileId=164016&pathId=1938870460 using System; +using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -14,10 +15,13 @@ public abstract class BaseEntity [Required] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + //TODO: Implement http://stackoverflow.com/a/38102266/2343739 so DefaultValue takes effect in db automatically + [DefaultValue("CURRENT_TIMESTAMP")] public DateTime AddedDateUtc { get; set; } [Required] [DatabaseGenerated(DatabaseGeneratedOption.Computed)] + [DefaultValue("CURRENT_TIMESTAMP")] public DateTime ModifiedDateUtc { get; set; } } } \ No newline at end of file