- Visual Studio 2022
- .NET 7.0
- ASP.NET Core Web API Project
- OS Windows10
- 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));