-
Notifications
You must be signed in to change notification settings - Fork 293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Always Encrypted Issue with EF Core 3.0 #271
Comments
Not sure if that's in EF or SqlClient, @roji does this sound like one of yours? |
Difficult to be sure without more info... I may be wrong, but AFAIK EF doesn't have any special behavior or support for Always Encrypted (i.e. it's a purely lower-level feature). @bngapiusr can you please post the full exception details, plus ideally a small code sample so we understand what you're doing? |
@bngapiusr With Always Encrypted, a lot of implicit conversions that used to work for a non-encrypted column do not work on encrypted columns. For example, type SqlClient driver does its best to derive the sql type from the client input value. For example, if the input value is To make this work with Always Encrypted, the client application will need to explicitly set the sqldbtype and provide the precision and scale of the parameter by using var parameter = new SqlParameter("@p1", SqlDbType.Decimal);
parameter.Precision = 18; // set to the precision of your encrypted column
parameter.Scale = 2; // set to the scale of your encrypted column
parameter.Value = 1100; // set to the value you're trying to insert
var commandText = "INSERT INTO YourTable (EncryptedColumnName) VALUES (@p1)";
context.Database.ExecuteSqlCommand(commandText, parameter); |
Thanks everyone for your help.
I only get this error when I try to insert, update and delete from an asp.net core 3 app. "Server=YourServerName;Database=CustomerDb;Trusted_Connection=True;Column Encryption Setting=Enabled;MultipleActiveResultSets=true" I also have a .Net Framwork and EF 6.3 mvc app that is using the same database and the Insert, update and delete functionality works great. |
sorry did not mean to close this issue. |
How is the definition of the column data type currently created? Is it done by EF or by you manually? |
@bngapiusr please provide a simple project that reproduces the issue, preferably not using EF Core. |
I think @yukiwongky's explanation is what you'll need if you're doing it manually. If EF Core needs more input to be able to create the parameters it'd be useful to know what it's currently using to do so. Either way a repro will be good. |
@Wraith2, the column data type are created by EF core using code first from an existing database. |
@roji do you know how to set parameter specific properties in EFCore? Such as the precision and the scale. @bngapiusr would be great if you can give us a repro script. |
@bngapiusr a simple repro project would be helpful here. In any case, when sending parameters to the database, EF Core doesn't currently set parameter facets (size, precision, scale) to match the corresponding column's definition. It could do this - but I think there were discussions in the past on why that wouldn't be a good idea. Always Encrypted may be a good reason to revisit that. @AndriySvyryd @smitpatel @ajcvickers do you have info on this? Should we open an issue in EF Core to discuss? |
Could be related to dotnet/efcore#17799. i.e. the temp table we created for saving has decimal(18,2). We should move this to EF Core, as it seems like integration issue in EF. |
@roji @yukiwongky download the project from this repo https://github.com/bngapiusr/AEDemo. |
Opened dotnet/efcore#18681 to track setting facets systematically on the EF Core side. This issue can probably be closed (leaving to the Sqlclient team). |
Closing as new issue is created on EFCore side. |
I'm trying to save data to always encrypted table in sqlserver 2016 database from asp.net 3.0 app but I'm getting Operand type clash: decimal(4,0) encrypted with... I'm using efcore 3.0 context.savechanges() method.
Is this supported in .Net 3.0 and where can I find examples on how to perform crud operations on always encrypted tables in .Net 3.0?
Any help will be appreciated,
Thanks,
Tony
The text was updated successfully, but these errors were encountered: