DbExpressionBuilder.SetClause给出了找不到方法的异常

时间:2015-12-21 17:18:02

标签: .net entity-framework entity-framework-6 interceptor soft-delete

我试图将删除命令更改为更新命令。但是以下一行

DbSetClause clause = DbExpressionBuilder.SetClause(property, now);

给了我一个例外。

{"Method not found: 'System.Data.Entity.Core.Common.CommandTrees.DbSetClause System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder.DbExpressionBuilder.SetClause(System.Data.Entity.Core.Common.CommandTrees.DbExpression, System.Data.Entity.Core.Common.CommandTrees.DbExpression)'."}

它假设是一个非常直接的代码。我不明白为什么它不起作用。

var deleteCommand = interceptionContext.OriginalResult as DbDeleteCommandTree;
            if (deleteCommand != null)
            {
                var column = "DeleteTime";
                if (column != null)
                {
                    var setClauses = new List<DbModificationClause>();
                    var table = (EntityType)deleteCommand.Target.VariableType.EdmType;
                    if (table.Properties.Any(p => p.Name == column))
                    {
                        DbVariableReferenceExpression variable = DbExpressionBuilder.Variable(deleteCommand.Target.VariableType, deleteCommand.Target.VariableName);
                        DbPropertyExpression property = DbExpressionBuilder.Property(variable, column);
                        DbExpression now = DbExpression.FromDateTime(DateTime.Now);
                        DbSetClause clause = DbExpressionBuilder.SetClause(property, now);
                        setClauses.Add(clause);
                    }

                    var update = new DbUpdateCommandTree(
                        deleteCommand.MetadataWorkspace,
                        deleteCommand.DataSpace,
                        deleteCommand.Target,
                        deleteCommand.Predicate,
                        setClauses.AsReadOnly(),
                        null);

                    interceptionContext.Result = update;
                }
            }

0 个答案:

没有答案