I’m using Entity Framework with MongoDB. I have a class, Account
with the following field:
private readonly byte[] salt;
Account is configured in Entity Framework like so:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Account>().ToCollection("accounts");
}
When I save an Account
to my database, the corresponding document does not have salt
.
How do I store a field or property in my database using Entity Framework whilst keeping it private?
2
Answers
Turns out I just needed to manually add the field for the model.
You should implement a Backing Field.
Salt
property with backing field:salt
.Salt
with the backing field in Fluent API.