Func<Comm_Dic, bool> aWhere = c => c.DicType == "频次管理" && c.Name=="订阅";
Class2.Update<Comm_Dic>(SMSDataContext, aWhere, c => c.Value = txt_Dingyue2.Text); Func<Comm_Dic, bool> aWhere1 = c => c.DicType == "频次管理" && c.Name == "非订阅";
Class2.Update<Comm_Dic>(SMSDataContext, aWhere1, c => c.Value = txt_Dingyue_no2.Text);我这2个更新的 该如何合并成一个;还有linq 更新多行的语句, 效果跟sql的
update set case
when then
when then
end where 语句一样的该怎么写
Class2.Update<Comm_Dic>(SMSDataContext, aWhere, c => c.Value = txt_Dingyue2.Text); Func<Comm_Dic, bool> aWhere1 = c => c.DicType == "频次管理" && c.Name == "非订阅";
Class2.Update<Comm_Dic>(SMSDataContext, aWhere1, c => c.Value = txt_Dingyue_no2.Text);我这2个更新的 该如何合并成一个;还有linq 更新多行的语句, 效果跟sql的
update set case
when then
when then
end where 语句一样的该怎么写
然后再遍历集合更新数据
所以无法实现一个更新语句更新两种条件的实体
但你可利用延迟查询特性
最后一次性提交持久化数据到数据库 即 submitchanges()操作
但是我是调用一个方法来更新的,这个方法是封装好的,总不能改方法吧,刚刚学linq,请指教下。。
/// <summary>
/// 更新数据
/// </summary>
/// <typeparam name="T">表实体</typeparam>
/// <param name="databasecontext"></param>
/// <param name="aWhere">条件</param>
/// <param name="aEntity">更新字段描述</param>
public static void Update<T>(this DataContext databasecontext, Func<T, bool> aWhere, Action<T> aEntity) where T : class
{
var sqlrows = databasecontext.GetTable<T>().AsQueryable().Where(aWhere);
foreach (var row in sqlrows)
{
aEntity(row); }
databasecontext.SubmitChanges();
}