EF 批量删除扩展

using ExpressionDemo.Visitor;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace ExpressionDemo.DBExtend
{
public static class ExpressionExtension
{
public static void BatchDelete<T>(this IQueryable<T> entities, Expression<Func<T, bool>> expr)
{
ConditionBuilderVisitor visitor = new ConditionBuilderVisitor();
visitor.Visit(expr);
string condition = visitor.Condition();

string sql = string.Format("DELETE FROM [{0}] WHERE {1};"
, typeof(T).Name//有可能还得根据泛型去获取
, condition);
//然后执行sql
}

}
}

posted @ 2022-02-16 11:08  FiberHomer  阅读(85)  评论(0编辑  收藏  举报