Long story short, we have spent the past few days creating a translation to add decrypt/encrypt by key into Entity Framework.
The following select works (the hardcoded key "test" is just for a testing environment, this will be stored with keystores later) The EF.Functions.Decrypt triggers a translation expression that writes custom SQL for Entity Framework to utilize the internal decryption methods.
var filteredSet = Set.Include(x => x.Table2)
.Where(x => x.Id == id)
.Where(x => x.Table2.IsSomething)
.Select(m => new Model
{
Id = m.Id,
Decrypted = EF.Functions.Decrypt("test", m.Encrypted), //string
Table2 = m.Table2,
Encrypted = m.Encrypted //byte[]
}).ToList();
The following (as I sort of expected going into it) does not.
public Model createNew(string Data)
{
Set.Add(
new Model
{
Encrypted = EF.Functions.Encrypt("test", Data)
}
);
return new Model();
}
When used in this manner it attempts to create a new model object using the EF Function and throws an InvalidOperationError. Is there a way to perform an Add in EF where it translates this function rather attempting the execute the code into a model?
Aucun commentaire:
Enregistrer un commentaire