Skip to content
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

Null reference exception when running UpdateFromQuery #476

Open
david-garcia-garcia opened this issue Mar 14, 2022 · 4 comments
Open

Null reference exception when running UpdateFromQuery #476

david-garcia-garcia opened this issue Mar 14, 2022 · 4 comments
Assignees

Comments

@david-garcia-garcia
Copy link

david-garcia-garcia commented Mar 14, 2022

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](Expression1 updateFactory)
at Z.EntityFramework.Extensions.BatchUpdate.[](IQueryable1 , Expression1 , SchemaEntityType1 ) at Z.EntityFramework.Extensions.BatchUpdate.Execute[T](IQueryable1 query, Expression1 updateFactory) at DbContextExtensions.[](IQueryable1 , Expression1 , Action1 , Boolean )
at DbContextExtensions.UpdateFromQuery[TEntity](IQueryable1 query, Expression1 updateExpression, Action1 bulkOperationFactory) at DbContextExtensions.UpdateFromQuery[TEntity](IQueryable1 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
@david-garcia-garcia
Copy link
Author

I can confirm this broke exactly in release: 6.13.0

@david-garcia-garcia
Copy link
Author

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.

@david-garcia-garcia
Copy link
Author

david-garcia-garcia commented Mar 14, 2022

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; });

@JonathanMagnan
Copy link
Member

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

@JonathanMagnan JonathanMagnan self-assigned this Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants