In EF 6 DBInterception, how to get the actual value from DbModificationClause clause?

Viewed 31

I'm researching with encrypting an EF 6 db column using db interceptors and custom annotation on the ef entity: https://www.codeguru.com/csharp/soft-deleting-entities-cleanly-using-entity-framework-6-interceptors/

However, the guide's example is using a static string to replace the value prior to inserting to the database. I need the original value to encrypt it and then use the new encrypted value to be inserted to the db but I can't seem to figure out how to get the original value.

public static DbModificationClause UpdateIfMatch(this DbModificationClause clause, string property)
        {
            var propertyExpression = (DbPropertyExpression)((DbSetClause)clause).Property;

            
            // Get the original value to be inserted to the DB
            // Encrypt that value and use it instead
             var newEncryptedValue = propertyExpression.GetValue()?

            if (propertyExpression.Property.Name == property)
            {
                return DbExpressionBuilder.SetClause(propertyExpression, DbExpression.FromString(newEncryptedValue));
            }
            return clause;
        }
0 Answers
Related