I'm making an application which is similar to a small network. I have this class :
class Person
{
public string Email {get; set;}
public string Password {get; set;}
public int Age {get; set;}
public long Birthday {get;set;}
... 30 properties more
}
I have this query :
_graphClient.Cypher.Match ("n:Person")
.Where<Person>(n => n.Email == info.Email)
.Return(n => n.As<Person>)
But I want my query ignore the password and return all other properties.
Exactly, I want it to be:
{
Email: "email_1",
Age : 10,
Birthday : 1000
... 30 properties more
}
Can anyone help me please?
Thank you.
There are three options I can think of, but I think only one is really viable for you. You can attach the attribute [JsonIgnore]
to your Password
property - but this will stop it being serialized ever - and I don't think you want that.
The second option is to use an Anonymous type for your return, so something like:
.Return(n => new {
Email = n.As<Person>().Email,
/* etc */
})
But I think that will mean you'll write a lot of code, which I imagine you'd rather avoid.
The final option is to have something like:
public class Person {
public string Email { get; set; }
/* All other properties, except Password */
}
public class PersonWithPassword : Person {
public string Password { get;set; }
}
Then use Person
where you are, and PersonWithPassword
where you need the password.
You might find you have a problem if you have a Membership set up to use Person
as is - in which case, you'd do something like:
public class PersonWithoutPassword {
public string Email { get; set; }
/* All other properties, except Password */
}
public class Person : PersonWithoutPassword {
public string Password { get;set; }
}
and in your return - you'd return:
Return(n => n.As<PersonWithoutPassword>())
instead.