C
C#14mo ago
OkOk

❔ Enabling "Always Encrypted" created a clash of datatypes

My normal working code
_dbContext.MyClass.Add(MyObject);
_dbContext.MyClass.Add(MyObject);
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
JakenVeina
JakenVeina14mo ago
what docs? what is _dbContext? what is nvarchar?
OkOk
OkOk14mo ago
The docs for Always Encrypted _dbContext is your run-of-the-mill pattern inheriting from dbContext nvarchar is a standard datatype in Sql-server
OkOk
OkOk14mo ago
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.
JakenVeina
JakenVeina14mo ago
that doesn't appear to reference EF Core at all how are you configuring this for EF Core?
OkOk
OkOk14mo ago
It does not, I don't seem to be able to find much about using Always Encrypted with EF.
JakenVeina
JakenVeina14mo ago
might not be supported reading the error, and similar errors online, it seems to me that EF is sending unencrpyted strings to the database
OkOk
OkOk14mo ago
But EF is just converted to normal SQL before reaching the DB?
JakenVeina
JakenVeina14mo ago
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
OkOk
OkOk14mo ago
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
JakenVeina
JakenVeina14mo ago
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
OkOk
OkOk14mo ago
Just looking at the database column, it claims that the datatype is just as before the encryption, a un-nullable nvarchar(max)
JakenVeina
JakenVeina14mo ago
but it's encrypted
OkOk
OkOk14mo ago
Is that a different datatype?
JakenVeina
JakenVeina14mo ago
which, from what I can tell, makes it NOT the same data type
OkOk
OkOk14mo ago
Okey because that is what I was wondering
JakenVeina
JakenVeina14mo ago
that's my understanding from looking at the docs and such for about 5 minutes, anyway
Accord
Accord14mo ago
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.
Want results from more Discord servers?
Add your server
More Posts