Skip to content

Instantly share code, notes, and snippets.

@mcintyre321
Created June 24, 2015 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcintyre321/1b9d8060acb39a4f39f0 to your computer and use it in GitHub Desktop.
Save mcintyre321/1b9d8060acb39a4f39f0 to your computer and use it in GitHub Desktop.
JsonProperty for Entity Framework
[ComplexType]
public class JsonProperty<T> where T : class
{
[Required]
public string Json { get; private set; }
protected JsonProperty()
{
this.SerializerSettings = new PolymorphicJsonSerializerSettings();
}
[NotMapped]
protected PolymorphicJsonSerializerSettings SerializerSettings { get; set; }
[NotMapped] //property mapped as JSON
public T Value
{
get { return Json == null ? null : JsonConvert.DeserializeObject<T>(Json, SerializerSettings); }
set { Json = value == null ? null : JsonConvert.SerializeObject(value, typeof(T), SerializerSettings); }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment