EntityFramework-Plus icon indicating copy to clipboard operation
EntityFramework-Plus copied to clipboard

Update not working with ObjectContext

Open Coder3333 opened this issue 4 years ago • 2 comments

1. Description

I have a very simple query that uses the old ObjectContext, instead of DbContext, and it fails when I try to perform an Update.

2. Exception

Exception message:
System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.Exception: Oops! A general error has occurred. Please report the issue including the stack trace to our support team: [email protected]

Stack trace:
at .[](IQueryable`1 )
   at Z.EntityFramework.Extensions.BatchUpdate.Execute[T](IQueryable`1 query, Expression`1 updateFactory)
   at DbContextExtensions.[](IQueryable`1 , Expression`1 , Action`1 , Boolean )
   at DbContextExtensions.UpdateFromQuery[TEntity](IQueryable`1 query, Expression`1 updateExpression, Action`1 bulkOperationFactory)
   at Z.EntityFramework.Plus.BatchUpdateExtensions.Update[T](IQueryable`1 query, Expression`1 updateFactory, Action`1 batchUpdateBuilder)
   at Z.EntityFramework.Plus.BatchUpdateExtensions.Update[T](IQueryable`1 query, Expression`1 updateFactory)

4. Any further technical details

I have traced the server, and no SQL is being executed.

Z.EntityFramework.Plus.EF6 5.1.31.0

Coder3333 avatar Apr 28 '21 15:04 Coder3333

Hello @Coder3333 ,

Thank you for reporting, we will look at it.

Best Regards,

Jon


Sponsorship Help us improve this library

Performance Libraries context.BulkInsert(list, options => options.BatchSize = 1000); Entity Framework ExtensionsBulk OperationsDapper Plus

Runtime Evaluation Eval.Execute("x + y", new {x = 1, y = 2}); // return 3 C# Eval FunctionSQL Eval Function

JonathanMagnan avatar Apr 28 '21 16:04 JonathanMagnan

Hello @Coder3333 ,

We didn't successfully implement it in our library.

However, we have a public extension method that could help you: GetOrCreateDbContext

Such as:

objectContext.GetOrCreateDbContext().Set<Customer>().Update(x => new Customer {Code = "zzz"});

Let me know if this workaround is working for you.

As you understand, this method returns a DbContext even if you are using purely an ObjectContext.

Best Regards,

Jon

JonathanMagnan avatar May 03 '21 02:05 JonathanMagnan