add JsonIgnore to BaseEntity properties

This commit is contained in:
Collin M. Barrett 2017-10-25 13:19:01 -05:00
parent 4182365203
commit 616823e03f
3 changed files with 6 additions and 24 deletions

View file

@ -90,21 +90,6 @@
"minLength": 6,
"maxLength": 2083,
"format": "uri"
},
"Id": {
"type": "integer"
},
"AddedDateUtc": {
"type": "string",
"default": "CURRENT_TIMESTAMP",
"format": "date-time"
},
"ModifiedDateUtc": {
"type": [
"string",
"null"
],
"format": "date-time"
}
},
"required": [
@ -117,9 +102,6 @@
"HomeUrl",
"IssuesUrl",
"Name",
"ViewUrl",
"Id",
"AddedDateUtc",
"ModifiedDateUtc"
"ViewUrl"
]
}

View file

@ -16,7 +16,7 @@ public static void WriteSampleToFile()
private static JObject GetSampleList()
{
var sampleList = (JObject) JToken.FromObject(new List
return (JObject) JToken.FromObject(new List
{
Author = "John Doe",
Description = "A sample list to filter out advertisements.",
@ -29,10 +29,6 @@ private static JObject GetSampleList()
Name = "My Sample List",
ViewUrl = "https://mysample.list/list.txt"
});
sampleList.Remove("Id");
sampleList.Remove("AddedDateUtc");
sampleList.Remove("ModifiedDateUtc");
return sampleList;
}
}
}

View file

@ -3,6 +3,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using FilterLists.Data.Models.Contracts;
using Newtonsoft.Json;
namespace FilterLists.Data.Models.Implementations
{
@ -10,15 +11,18 @@ public abstract class BaseEntity : IBaseEntity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[JsonIgnore]
public long Id { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[JsonIgnore]
//TODO: Implement http://stackoverflow.com/a/38102266/2343739 so DefaultValue takes effect in db automatically
//For now, manually execute on new tables: InitializeNewTableBaseEntityDefaults.sql
[DefaultValue("CURRENT_TIMESTAMP")]
public DateTime AddedDateUtc { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
[JsonIgnore]
public DateTime? ModifiedDateUtc { get; set; }
}
}