yessql icon indicating copy to clipboard operation
yessql copied to clipboard

[Question] Is it possible to add an attribute to a property to ignore it on save?

Open PizzaConsole opened this issue 5 years ago • 7 comments

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?

PizzaConsole avatar Nov 03 '20 01:11 PizzaConsole

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

hishamco avatar Nov 03 '20 06:11 hishamco

[JsonIgnore] and all other attributes are supported when serializing data.

deanmarcussen avatar Nov 03 '20 08:11 deanmarcussen

@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; }

    }

PizzaConsole avatar Nov 03 '20 08:11 PizzaConsole

I forgot that we are JSON serializer by default ;)

hishamco avatar Nov 03 '20 09:11 hishamco

@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.

PizzaConsole avatar Nov 05 '20 23:11 PizzaConsole

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

hishamco avatar Nov 06 '20 09:11 hishamco

Any update on this? Should I try to look into doing it myself and doing a PR?

PizzaConsole avatar Jan 25 '21 17:01 PizzaConsole