I recently encrypted a column in SSMS using the Encrypt Columns functionality using randomised encryption. The column's data type is varchar(200)
and the property in C# is string
with MaxLength(200)
.
I have this code:
var user = ctx.ActiveUsers
.Include(u => u.UserLocations.Select(ul => ul.Location.Region))
.Include(u => u.UserReadOnlyLocations)
.FirstOrDefault(u => u.Username == username);
where UserReadOnlyLocations
is an object that contains Location
as a navigational property.
When I remove either the first or second .Include
so there is only one, this works without error. However if I run it as above, I get the error:
SqlException: Operand type clash: varchar is incompatible with varchar(200) encrypted with (encryption_type = 'RANDOMIZED', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'cek', column_encryption_key_database_name = 'DB') collation_name = 'Latin1_General_BIN2'
Is there a fix/workaround for this?