My requirement is to create common
class library to use between EntityFramework
project and JSON
serialization project.I ended up with below class and properties which is decorated by Newtonsoft.Json
and System.Runtime.Serialization
attributes.
I feel, it's over burden. Can I use only Newtonsoft.Json
attributes, so that I can remove all System.Runtime.Serialization
attributes. If I do so, will my code first entity framework
able to generate required schema in database?
[DataContract]
public partial class CompanyGroup:BaseEntity
{
[DataMember(Name = "Id")]
public string Id { get; set; }
[JsonProperty("Name", Required = Required.Always)]
[Required]
[DataMember(Name = "Name")]
public string Name { get; set; }
}
Also, I see [JsonRequired]
attribute, how it is different from [Required]
?
Is System.ComponentModel.DataAnnotations
is enough for EF?
Basically what is the best practice while writing the common
class libraries?