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

Could not find the context from IQueryable expression #48

Closed tomasbruckner closed 4 years ago

tomasbruckner commented 4 years ago

EF Classic throws for me could not find context and I am not sure why.

This throws Could not find the context from the IQueryable expression. Are you sure this is coming from an Entity Framework Context?

await _db.Items
    .Where(o => o.HierarchyId == fromHierarchyId)
    .UpdateFromQueryAsync(
        o => new Item {HierarchyId = toHierarchyId}
    );
await _db.SaveChangesAsync();

But this works fine

var list = await _db.Objects
    .Where(o => o.HierarchyId == fromHierarchyId)
    .ToListAsync();
list.ForEach(o => {
  o.HierarchyId = toHierarchyId;
});
await _db.SaveChangesAsync();

What am I missing?

I am using Z.EntityFramework.Classic 7.1.17 EF Core 2.2.6 .NET Core 2.2

JonathanMagnan commented 4 years ago

Hello @tomasbruckner ,

Is it possible for you to provide a runnable project with this issue (not the full project code, just a sample project with the issue)? This kind of issue usually happen when a third party library interferes with the query.

JonathanMagnan commented 4 years ago

Hello @tomasbruckner

Since our last conversation, we haven't heard from you!

In order for us to help you better, don't hesitate to provide us a sample of the project with the same issue.

Looking forward to hearing from you,

Jon

alikrc commented 4 years ago

i'm getting same error with .net framework 4.7.2

JonathanMagnan commented 4 years ago

Hello @alikrc ,

Do be able to investigate it, we will need a runnable project.

Best Regards,

Jon