yessql
yessql copied to clipboard
[Question] Is it possible to add an attribute to a property to ignore it on save?
i.e. :
public class BlogPost
{
public string Title { get; set; }
public string Author { get; set; }
public string Content { get; set; }
public DateTime PublishedUtc { get; set; }
public string[] Tags { get; set; }
[NotMapped]
public string Ignore { get; set; }
}
Is there something to this effect?
AFAIK there's no such this supported yet, but it's useful, @sebastienros it's fine to support it, if YES, I can send a PR
[JsonIgnore] and all other attributes are supported when serializing data.
@deanmarcussen @hishamco That works!
public class BlogPost
{
public string Title { get; set; }
public string Author { get; set; }
public string Content { get; set; }
public DateTime PublishedUtc { get; set; }
public string[] Tags { get; set; }
[JsonIgnore]
public string DoNotSave { get; set; }
}
I forgot that we are JSON serializer by default ;)
@deanmarcussen @hishamco I just realized that there is still an issue here. Because YesSql uses Newtonsoft as the serializer, if you have [JsonIgnore] on a property and you try to return that object from your Controller and are using Newtonsoft as your Controller serializer then it will also ignore that property. Thus leaving that property as null when the client gets the serialized object.
In other words, I Believe it would be unwise to rely on a serializer attribute from a 3rd party library to determine if a user wants a property saved using YesSql.
May be we can introduce a Ignore attribute something similar to NotMapped in EF, but I think this would need a little of work to remove the property after serialization process regardless of the serializer that has been used
Any update on this? Should I try to look into doing it myself and doing a PR?