KEMBAR78
EntityFrameworkCore 7 SetProperty(avar,avalue) Unable to cast object of type 'System.Linq.Expressions.TypedParameterExpression' to type 'System.Linq.Expressions.LambdaExpression'. · Issue #31349 · dotnet/efcore · GitHub
Skip to content

EntityFrameworkCore 7 SetProperty(avar,avalue) Unable to cast object of type 'System.Linq.Expressions.TypedParameterExpression' to type 'System.Linq.Expressions.LambdaExpression'. #31349

@2366621450

Description

@2366621450
  1. Visual Studio 2022
  2. .NET 7.0
  3. ASP.NET Core Web API Project
  4. OS Windows10
  5. Microsoft.EntityFrameworkCore 7.0.9

My code:
1.Error

ADal aDal = new ADal();

Func<AModel, float> p = property => property.Balance;

aDal._databaseContext
.ModelDbSet
.Where(w => w.ID == 5)
.Take(1)
.ExecuteUpdate(e => e.SetProperty(p, 636));

Out error (Almost no answer found online):
引发的异常:“System.InvalidCastException”(位于 System.Private.CoreLib.dll 中)

“System.InvalidCastException”类型的未经处理的异常在 System.Private.CoreLib.dll 中发生

Unable to cast object of type 'System.Linq.Expressions.TypedParameterExpression' to type 'System.Linq.Expressions.LambdaExpression'.

2.Normal (Do not use : Func<AModel, float> p = property => property.Balance;)

ADal aDal = new ADal();

aDal._databaseContext
.ModelDbSet
.Where(w => w.ID == 5)
.Take(1)
.ExecuteUpdate(e => e.SetProperty(p => p.Balance, 636));

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions