leonardoporro / Detached-Mapper

An ORM friendly mapper. Allows saving entire entity graphs. Heavily inspired in GraphDiff and AutoMapper.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EntityFrameworkCore.Query.NavigationBaseIncludeIgnored Error

PatAmb63 opened this issue · comments

I am using your package for long time. Recently, I update all the packages (yours and EntityFramework as well) and I cannot use _dbContext.MapAsync() function.

I have the following error message.

System.InvalidOperationException: An error was generated for warning 'Microsoft.EntityFrameworkCore.Query.NavigationBaseIncludeIgnored': The navigation 'LigneFacture.Facture' was ignored from 'Include' in the query since the fix-up will automatically populate it. If any further navigations are specified in 'Include' afterwards then they will be ignored. Walking back include tree is not allowed.

I am lost, i don't know how to solve it.

Could you tell me how i can solve the problem ?

Hi @PatAmb63,
Thanks, I'm glad you found it useful.

There was a change in EF, and now it complains if you include base navigations, e.g.:
dbContext.Include("MyNavigation").Include("MyNavigation.OtherNavigation");
Which is what Detached unfortunately is doing...

Please try one of these workarounds:

  • revert to an older version of EF, such as 6.0.0
    OR
  • configure EF to ignore the warning:
using Microsoft.EntityFrameworkCore.Diagnostics;
services.AddDbContext<MainDbContext>(cfg =>
{
    cfg.UseSqlServer(...);
    cfg.UseDetached();

        cfg.ConfigureWarnings(w => w.Ignore(CoreEventId.NavigationBaseIncludeIgnored)
    );
});

Sorry for the issue, I'll be working this weekend to improve the query.
I made a large refactor for a sponsor (and because it was needed). pls, let me know if you find something else.
And please stay in touch! knowing that people is using the library motivates me to keep improving it.

Cheers,

Hello,

I tried to use this :

using Microsoft.EntityFrameworkCore.Diagnostics;
services.AddDbContext<MainDbContext>(cfg =>
{
    cfg.UseSqlServer(...);
    cfg.UseDetached();

        cfg.ConfigureWarnings(w => w.Ignore(CoreEventId.NavigationBaseIncludeIgnored)
    );
});

With your latest version of the package i have a problem when use the following :

  • Use _dbContext.MapAsync() many time in a foreach loop
  • Use Ef core to create new entity in the database.

The first time the new entity is created correctly, but the second loop i've got error for foreign key already exist.

Maybe something is not cleared in MapAsync() function ?

I hope it can help you to improve the package.

Right now i need to use the package 6.0.6

BR
Patrice

Hi Patrice,
NavigationBaseIncludeIgnored was fixed in 6.2.2. The workaround should not be needed anymore.
I'm researching the loop issue..
Tests are greatly appreciated, is there any small piece of code that you could submit to make it easier for me to reproduce?
I will preserve all submited tests in the contrib folder, to ensure that new changes don't break existing code for anyone.

Thanks!

Hello,
Sorry for my late answer
I was reluctant to update to new version, but as you asked me to test, yesterday i updated to 6.2.2.
Now i need to use o.Ignore(CoreEventId.InvalidIncludePathError)
I don't know if you know why
BR
Patrice

It should be fixed in 7.0+
please reopen if not