Tell RavenDB to ignore a property

c#, ravendb

Solution

Just decorate the `Duration` property with `[JsonIgnore]` like this:

public class Build
{
    public string Id { get; set; }
    public string Name { get; set; }
    public DateTime StartedAt { get; set; }
    public DateTime FinishedAt { get; set; }

    [Raven.Imports.Newtonsoft.Json.JsonIgnore]
    //[Newtonsoft.Json.JsonIgnore] // for RavenDB 3 and up
    public TimeSpan Duration { get { return StartedAt.Subtract(FinishedAt); }}
}

See more here: http://ravendb.net/docs/client-api/advanced/custom-serialization

Problem

I have a document model to store in RavenDB but I don't want to store a calculated property. How do I tell RavenDB to ignore this property? In the below example I don't want to store `Duration`. ``` public class Build { public string Id { get; set; } public string Name { get; set; } public DateTime StartedAt { get; set; } public DateTime FinishedAt { get; set; } public TimeSpan Duration { get { return StartedAt.Subtract(FinishedAt); }} } ```

Original source