You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When reading from a "Date" column that utilizes column-level encryption in SQLServer using Entity Framework, an InvalidCastException occurs in SQLDataReader.cs, on the line "return (T)GetValueFromSqlBufferInternal(data, metaData);". The issue arises because the GetValueFromSqlBufferInternal call is returning a DateTime type instead of the expected DateOnly type, leading to the exception. The issue does not occur without column-level encryption.
Exception message:
System.InvalidCastException : Unable to cast object of type 'System.DateTime' to type 'System.DateOnly'
Stack trace:
at Microsoft.Data.SQLClient.SQLDataReader.GetFieldValueFromSqlBufferInternal[T](SQLBuffer data, _SqlMetadata metadata, Boolean isAsync)
at Microsoft.Data.SQLClient.SQLDataReader.GetFieldValueInternal[T](Int32 i, Boolean isAsync)
at Microsoft.Data.SQLClient.SQLDataReader.GetFieldValue[T](Int32 i)
at lambda_method153(Closure, QueryContext, DBDataReader, ResultContext, SingleQueryResultCoordinator)
To reproduce
publicclassEncryptedDate{publicintId{get;set;}publicDateOnlyDob{get;set;}}publicclassEFCoreTestContext:DbContext{publicDbSet<EncryptedDate>EncryptedDates{get;set;}}staticvoidMain(){/*Note - insert at least one value into the table before running this, and encrypt the Dob column to type "randomized" in SQLServer*/using(varcontext=newEFCoreTestContext()){vardate=context.EncryptedDates.First();}}
Expected behavior
Row reads correctly from the database.
Further technical details
Microsoft.Data.SqlClient version: 5.1.2
.NET target: .NET 8
SQL Server version: SQL Server 2019
Operating system: Windows 10 Pro
Additional context
Removing column-level encryption in SQL Server allows the above code to run correctly.
The text was updated successfully, but these errors were encountered:
Describe the bug
When reading from a "Date" column that utilizes column-level encryption in SQLServer using Entity Framework, an InvalidCastException occurs in SQLDataReader.cs, on the line "return (T)GetValueFromSqlBufferInternal(data, metaData);". The issue arises because the GetValueFromSqlBufferInternal call is returning a DateTime type instead of the expected DateOnly type, leading to the exception. The issue does not occur without column-level encryption.
To reproduce
Expected behavior
Row reads correctly from the database.
Further technical details
Microsoft.Data.SqlClient version: 5.1.2
.NET target: .NET 8
SQL Server version: SQL Server 2019
Operating system: Windows 10 Pro
Additional context
Removing column-level encryption in SQL Server allows the above code to run correctly.
The text was updated successfully, but these errors were encountered: