EntityFramework-Extensions
EntityFramework-Extensions copied to clipboard
UpdateFromQuery fails using related entity with inheritance (EF and EF Core)
Description
UpdateFromQuery
fails when using related entity if the updated entity is of a derived entity type.
Note that if inheritance is not involved, then it succeeds in EF, but still fails in EF Core.
Exception
System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'PropInRelated'.
Invalid column name 'PropInRelated'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at .(DbCommand , BulkOperation , Int32 )
at .(DbCommand , BulkOperation , Int32 )
at .( )
at .Execute(List`1 actions)
at .(List`1 )
at Z.BulkOperations.BulkOperation.()
at Z.BulkOperations.BulkOperation`1.UpdateFromQuery(IQueryable originalQuery, IQueryable query, Expression`1 updateExpression)
at DbContextExtensions.[](IQueryable`1 , Expression`1 , Action`1 , Boolean )
at DbContextExtensions.UpdateFromQuery[TEntity](IQueryable`1 query, Expression`1 updateExpression, Action`1 bulkOperationFactory)
at DbContextExtensions.UpdateFromQuery[TEntity](IQueryable`1 query, Expression`1 updateExpression)
at Program.InheritanceUpdateForOwnBasePropertiesUsingRelatedBaseProperties() in d:\Windows\Temp\unw5nk5o.0.cs:line 123
at lambda_method(Closure )
at Program.RunTest(Expression`1 test) in d:\Windows\Temp\unw5nk5o.0.cs:line 90
ClientConnectionId:d16e6408-4199-4cef-b963-246cb7f84ba5
Error Number:207,State:1,Class:16
Fiddle or Project (Optional)
EF https://dotnetfiddle.net/hPWCcL
EF Core https://dotnetfiddle.net/g4Rq0T
Further technical details
- EF version: EF 6.4 and EF Core 6.0.4
- EF Extensions version: Z.EntityFramework.Extensions 6.13.17 and Z.EntityFramework.Extensions.EFCore 6.13.17
- Database Provider: SQL Server
Hello @davidnemeti ,
Unfortunately, that's currently unsupported.
However, we are currently working hard to recode some parts of our library to be able to handle more complex scenarios like this one. I cannot provide any expected date but I believe it will come during this summer.
Best Regards,
Jon