Created
June 24, 2015 09:21
-
-
Save mcintyre321/1b9d8060acb39a4f39f0 to your computer and use it in GitHub Desktop.
JsonProperty for Entity Framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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