❔ Enabling "Always Encrypted" created a clash of datatypes
My normal working code crashes when enabling encryption and saving.
Operand type clash: nvarchar is incompatible with nvarchar(4000) encrypted..
I tried changing forcing the nvarchar to 4000 and I enabled everything I saw in the docs.
17 Replies
what docs?
what is _dbContext?
what is nvarchar?
The docs for Always Encrypted
_dbContext is your run-of-the-mill pattern inheriting from dbContext
nvarchar is a standard datatype in Sql-server
Tutorial: Getting started with Always Encrypted - SQL Server
This tutorial teaches you how to encrypt columns using Always Encrypted and how to query encrypted columns in SQL Server, Azure SQL Database, and Azure SQL Managed Instance.
that doesn't appear to reference EF Core at all
how are you configuring this for EF Core?
It does not, I don't seem to be able to find much about using Always Encrypted with EF.
might not be supported
reading the error, and similar errors online, it seems to me that EF is sending unencrpyted strings to the database
But EF is just converted to normal SQL before reaching the DB?
which the database treats as values that are incompatible with an encrypted column
which makes sense, the entire point of Always Encrypted is that the database never sees the unencrypted values
EF would have to be instructed about which columns need to be encrpyted before being sent
yes, and that's the part it can't do correctly
I was wondering if the DB would intelligently look at the data and see it is unencrypted and reject it, or if it wouldn't matter as long as the data is not over 4000 nvarchars
nope
EF doesn't work that way
EF's concept of what the database is is 100% based on the EF modeling code you either write or have generated
if you don't tell it which columns are encrypted, it can't know
Just looking at the database column, it claims that the datatype is just as before the encryption, a un-nullable nvarchar(max)
but it's encrypted
Is that a different datatype?
which, from what I can tell, makes it NOT the same data type
Okey because that is what I was wondering
that's my understanding from looking at the docs and such for about 5 minutes, anyway
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.