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

ExecuteUpdateAsync don't work when using "modelBuilder.Entity<Country>().Navigation(e => e.MyFile).AutoInclude();" in Context #30250

Closed
Andrey-2021 opened this issue Feb 10, 2023 · 2 comments

Comments

@Andrey-2021
Copy link

Please check.

I have
`class Country
{
public int MenuPosition { get; set; }

public int? MyFileId { get; set; }
public MyFile? MyFile { get; set; }
}
`

when in context
I include AutoInclude:

`public class SqlDbContext : DbContext

{

protected override void OnModelCreating(ModelBuilder modelBuilder)

{
      modelBuilder.Entity<Country>().Navigation(e => e.MyFile).AutoInclude();
}

}
`

It's NOT work:
(where TEntity - Country)
public async Task ChangingMenuPositionAsync(TEntity entity)
{
...
var n = await db.Set()
.Where(x => x.MenuPosition >= entity.MenuPosition)
.ExecuteUpdateAsync(s => s.SetProperty(b => b.MenuPosition, b => b.MenuPosition + 1));
...
}

But,
if we DELETE
modelBuilder.Entity<Country>().Navigation(e => e.MyFile).AutoInclude();

It's WORK !!!
var n = await db.Set<TEntity>() .Where(x => x.MenuPosition >= entity.MenuPosition) .ExecuteUpdateAsync(s => s.SetProperty(b => b.MenuPosition, b => b.MenuPosition + 1));


System.InvalidOperationException: "The LINQ expression 'DbSet()
.Where(c => c.MenuPosition >= __entity_MenuPosition_0)
.LeftJoin(
inner: DbSet(),
outerKeySelector: c => EF.Property<int?>(c, "MyFileId"),
innerKeySelector: m => EF.Property<int?>(m, "Id"),
resultSelector: (o, i) => new TransparentIdentifier<Country, MyFile>(
Outer = o,
Inner = i
))
.Select(c => IncludeExpression(
EntityExpression:
c.Outer,
NavigationExpression:
c.Inner, MyFile)
)
.ExecuteUpdate(s => s.SetProperty(
propertyExpression: b => b.MenuPosition,
valueExpression: b => b.MenuPosition + 1))' could not be translated. Additional information: The following lambda argument to 'SetProperty' does not represent a valid property to be set: 'b => b.MenuPosition'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information."


Microsoft.EntityFrameworkCore 7.0.0.
Microsoft.EntityFrameworkCore.SqlServer 7.0.0.
Microsoft Visual Studio Community 2022 (64) 17.4.4

@ajcvickers
Copy link
Contributor

Duplicate of #28727

@ajcvickers ajcvickers marked this as a duplicate of #28727 Feb 10, 2023
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Feb 15, 2023
@Andrey-2021
Copy link
Author

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants