zzzprojects / EntityFramework-Classic

Entity Framework Classic is a supported version of the latest EF6 codebase. It supports .NET Framework and .NET Core and overcomes some EF limitations by adding tons of must-haves built-in features.
https://entityframework-classic.net
Other
102 stars 27 forks source link

Error when using UpdateFromQuery on an expanded query (Linqkit) #61

Closed shtifanov closed 3 years ago

shtifanov commented 3 years ago

Hi,

we have noticed that the UpdateFromQuery()/DeleteFromQuery() methods does not work with an expanded query. I've created a small runnable example where this problem can be reproduced.

private static Expression<Func<Customer, bool>> _testFilterExpression = c => c.Name == "abc";

public static void Main(string[] args)
{

    try
    {
        var ctx = new TestContext();
        var simpleRequest = ctx.Customers.Count();

        // this works
        var batchUpdate = ctx.Customers
            .Where(c => c.Name == "abc")
            .UpdateFromQuery(c => new Customer { Name = "Test" });

        // this crushes
        var batchLinqKitUpdate = ctx.Customers
            .AsExpandable()
            .Where(c => _testFilterExpression.Invoke(c) && c.Id > 0)
            .UpdateFromQuery(c => new Customer { Name = "Test" });
    }
    catch (Exception e)
    {

    }
}

System.Exception: Could not find the context from the IQueryable expression. Are you sure this is coming from an Entity Framework Context? at .[](IQueryable1 ) at DbContextExtensions.[](IQueryable1 , Expression1 , Action1 , Boolean ) at DbContextExtensions.Update efClassicAndLinqKit.zip FromQuery[TEntity](IQueryable1 query, Expression1 updateExpression, Action1 bulkOperationFactory) at DbContextExtensions.UpdateFromQuery[TEntity](IQueryable1 query, Expression`1 updateExpression) at ConsoleApp.Program.Main(String[] args) in C:\dev\test_projects\efClassicAndLinqKit\ConsoleApp\Program.cs:line 28

Maybe you can give me a hint, what is wrong here?

I'm using Z.EntityFramework.Classic 7.1.34 LinqKit.Z.EntityFramework.Classic 1.1.17 efClassicAndLinqKit.zip

JonathanMagnan commented 3 years ago

Hello @shtifanov ,

I'm not sure if we will succeed to make it works but we will look at it.

Best Regards,

Jon

JonathanMagnan commented 3 years ago

Hello @shtifanov ,

Sorry for the long waiting,

The v7.1.36 has been released.

Let me know if it's now working correctly with LinqKit.

Best Regards,

Jon

shtifanov commented 3 years ago

Hello @JonathanMagnan , it seems to work. Thank you for your effort!