-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Closed
Copy link
Description
lib
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0-alpha.1" />code
//success
await _ncdcDbContext.Set<LogicDatabaseEntity>().Where(o => o.Id == id).ExecuteUpdateAsync(o => o.SetProperty(p => p.IsDelete, p => true));
//error
await _ncdcDbContext.Set<LogicDatabaseEntity>().Where(o => o.Id == id).LogicDeleteAsync();
public static class QueryableExtension
{
public static Task<int> LogicDeleteAsync<T>(this IQueryable<T> queryable) where T:ILogicDelete
{
return queryable.ExecuteUpdateAsync(o => o.SetProperty(p => p.IsDelete, p => true));
}
}
public interface ILogicDelete
{
bool IsDelete { get; set; }
}
public class LogicDatabaseEntity:ILogicDelete
{
public string DatabaseName { get; set; } = null!;
public bool IsDelete { get; set; }
}error
The LINQ expression 'DbSet<LogicDatabaseEntity>()
.Where(l => l.IsDelete == False)
.Where(l => l.Id == __id_0)
.ExecuteUpdate(o => o.SetProperty<bool>(
propertyExpression: p => ((ILogicDelete)p).IsDelete,
valueExpression: p => True))' could not be translated. Additional information: The following lambda argument to 'SetProperty' does not represent a valid property to be set: 'p => ((ILogicDelete)p).IsDelete'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
System.InvalidOperationException: The LINQ expression 'DbSet<LogicDatabaseEntity>()
.Where(l => l.IsDelete == False)
.Where(l => l.Id == __id_0)
.ExecuteUpdate(o => o.SetProperty<bool>(
propertyExpression: p => ((ILogicDelete)p).IsDelete,
valueExpression: p => True))' could not be translated. Additional information: The following lambda argument to 'SetProperty' does not represent a valid property to be set: 'p => ((ILogicDelete)p).IsDelete'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass12_0`1.<ExecuteAsync>b__0()
at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.RelationalQueryableExtensions.ExecuteUpdateAsync[TSource](IQueryable`1 source, Expression`1 setPropertyCalls, CancellationToken cancellationToken)
at NCDC.EntityFrameworkCore.QueryableExtension.LogicDeleteAsync[T](IQueryable`1 queryable) in /Users/xuejiaming/Desktop/githubs/OpenConnector/src/orm/NCDC.EntityFrameworkCore/QueryableExtension.cs:line 8
at NCDC.WebBootstrapper.Controllers.LogicDatabase.LogicDatabaseController.Delete(String id) in /Users/xuejiaming/Desktop/githubs/OpenConnector/src/bootstrapper/NCDC.WebBootstrapper/Controllers/LogicDatabase/LogicDatabaseController.cs:line 104
at lambda_method235(Closure , Object )
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)Reactions are currently unavailable