EntityFramework-Extensions
EntityFramework-Extensions copied to clipboard
Null reference exception when running UpdateFromQuery
Description
Null reference exception when running UpdateFromQuery
dcs.CurrentContext.SABENTIS_COMPANY .Where(i => i.cif.Contains(" ")) .UpdateFromQuery(i => new SABENTIS_COMPANY() { cif = i.cif.Replace(" ", string.Empty) });
Exception
Exception message: {"Object reference not set to an instance of an object."}
Stack trace:
at Z.EntityFramework.Extensions.BatchUpdate.<>c.(MemberExpression )
at 1.Visit(Expression expression) at System.Linq.Expressions.ExpressionVisitor.VisitArguments(IArgumentProvider nodes) at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node) at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor) at
1.Visit(Expression expression)
at Z.EntityFramework.Extensions.BatchUpdate.ResolveUpdateFromQueryDictValuesMemberInit(Dictionary2 dictValues, Type entityType, MemberInitExpression memberInitExpression, String prefix) at Z.EntityFramework.Extensions.BatchUpdate.ResolveUpdateFromQueryDictValues[T](Expression
1 updateFactory)
at Z.EntityFramework.Extensions.BatchUpdate.[](IQueryable1 , Expression
1 , SchemaEntityType1 ) at Z.EntityFramework.Extensions.BatchUpdate.Execute[T](IQueryable
1 query, Expression1 updateFactory) at DbContextExtensions.[](IQueryable
1 , Expression1 , Action
1 , Boolean )
at DbContextExtensions.UpdateFromQuery[TEntity](IQueryable1 query, Expression
1 updateExpression, Action1 bulkOperationFactory) at DbContextExtensions.UpdateFromQuery[TEntity](IQueryable
1 query, Expression`1 updateExpression)
Fiddle or Project (Optional)
https://github.com/david-garcia-garcia/zzzbrokenmerge
Test for this specific issue in the project is:
TestMethod3
Further technical details
- EF version: 6.4.4
- EF Extensions version: 6.13.12
- Database Provider: MS SQL Server
I can confirm this broke exactly in release: 6.13.0
When this was working the outputed SQL was quite acceptable:
exec sp_executesql N'MERGE INTO [dbo].[CORE_LOCALES_SOURCE] AS DestinationTable USING ( SELECT [Extent1].[id] AS [id] FROM [dbo].[CORE_LOCALES_SOURCE] AS [Extent1] WHERE [Extent1].[source] LIKE N''% %'' ) AS StagingTable ON StagingTable.[id] = DestinationTable.[id] WHEN MATCHED THEN UPDATE SET [source] = REPLACE(DestinationTable.[source], N'' '', @p__linq__0_1) ;',N'@p__linq__0_1 nvarchar(4000)',@p__linq__0_1=N''
This totally looks like a regresion in the 6.13.0 release.
This does not work:
EntityFrameworkManager.BulkOperationBuilder = builder => { builder.UseLegacyBatchOperation = true; };
But if you set the legacy behaviour directly on the operation it does work:
db.CORE_LOCALES_SOURCE .Where(i => i.source.Contains(" ")) .UpdateFromQuery( i => new CORE_LOCALES_SOURCE() { source = i.source.Replace(" ", string.Empty) }, (o) => { o.UseLegacyBatchOperation = true; });
Hello @david-garcia-garcia ,
The v6.13.17 has been released.
The initial issue should now be fixed. My developer also fixed the BulkOperationBuilder
which was not used to check if the UseLegacyBatchOperation
value.
Let me know if everything works as expected.
Best Regards,
Jon