linq to sql批量删除
一般的sql批量就直接delete from table where id in (1,2,3,4,5)这样的,1,2,3,4,5是后台选中复选框传过来的id,
问,linq to sql要怎么写?(除了用存储过程)
我下面的这个貌似生成的不行,谁能给我个好的可以运行的列子测试的,谢谢。在线等
public static Expression<Func<T, bool>> GetConditionExpression<T>(this Table<T> table, string[] options, string fieldName) where T : class
{
ParameterExpression left = Expression.Parameter(typeof(T), "c");//c=>
Expression expression = Expression.Constant(false);
foreach (var optionName in options)
{
Expression right = Expression.Call
(
Expression.Property(left, typeof(T).GetProperty(fieldName)), //c.DataSourceName
typeof(string).GetMethod("Contains", new Type[] { typeof(string) }),// 反射使用.Contains()方法
Expression.Constant(optionName) // .Contains(optionName)
);
expression = Expression.Or(right, expression);//c.DataSourceName.contain("") || c.DataSourceName.contain("")
}
Expression<Func<T, bool>> finalExpression
= Expression.Lambda<Func<T, bool>>(expression, new ParameterExpression[] { left });
return finalExpression;
}