Castle ActiveRecord 如何条件批量更新或删除多条记录

jzywh 2008-03-25 10:44:41
Castle ActiveRecord 如何条件批量更新或删除多条记录?

例如希望实现功能 sql = "update Clothes set ClothesTypeId = null where ClothesTypeId = 1",

该如何做呢? 可以在SimpleQuery中写update语句么?
...全文
393 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiejiep 2010-04-19
  • 打赏
  • 举报
回复
关注。。。
DoNotTomcat 2008-04-07
  • 打赏
  • 举报
回复
ISessionFactoryHolder sessionHolder = ActiveRecordMediator.GetSessionFactoryHolder();
ISession session = sessionHolder.CreateSession(typeof(News));


try
{
System.Data.IDbCommand command = session.Connection.CreateCommand();
command.CommandText = "update news set IsPassed=" + IsPassed + " ,checkerList='" + adminRealName + "' WHERE id in('" + NewsIdList + "')";
command.ExecuteNonQuery();

}
catch (Exception e)
{
throw e;
}

sessionHolder.ReleaseSession(session);
MyNameEPC 2008-04-01
  • 打赏
  • 举报
回复
The most efficient way is writing a sql query to do this. Castle support build-in query execution.
jzywh 2008-03-26
  • 打赏
  • 举报
回复
Update 呢?
nutpp 2008-03-25
  • 打赏
  • 举报
回复
批量删除
ActiveRecordMediator.DeleteAll(typeof(T), where);


ActiveRecordMediator.DeleteAll(typeof(T), "ClothesTypeId = 1");

T为对应的实体类
nutpp 2008-03-25
  • 打赏
  • 举报
回复
ActiveRecordMediator.DeleteAll(typeof(T), where);

13,190

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 分析与设计
社区管理员
  • 分析与设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧