class using BsonIgnore. But it is ignoring the total object.public class User { public string Username { get; set; } public string Password { get; set; } [BsonIgnore,JsonProperty(PropertyName = "CreateDate")] public ICollection<Role> Roles { get; set; } } public class Role { public int RoleId {get; set;} public string RoleName { get; set; } public DateTime CreateDate { get; set;} }
I have 2 question.
- How to ignore only certain properties inside a class? I should not use
BsonIgnore directly inside Role class. - How to ignore multiple properties? Something like below.
Code:
[BsonIgnore,JsonProperty(PropertyName = "CreateDate")] [BsonIgnore,JsonProperty(PropertyName = "RoleId")] public ICollection<Role> Roles { get; set; }