【问题标题】:Subsonic Delete multiple records亚音速删除多条记录
【发布时间】:2011-12-09 00:19:00
【问题描述】:

我有一个表,它有两个字段,用户 ID 和学位 ID。一个用户可以在此表中拥有多个学位。当用户选择他们的学位时,我想删除数据库中已经存在但用户未选择的任何学位 ID。应该怎么做?我尝试使用这样的东西没有运气。

repo.DeleteMany(x=>x.MeetingAttendeeUserID==userID && x.EducationDegreeID userDegreeList)

谢谢, 刘易斯

【问题讨论】:

    标签: subsonic


    【解决方案1】:

    你能做这样的事吗?

    repo.DeleteMany(x =>
        x.MeetingAttendeeUserId == userID &&
        x.EducationDegreeID != selectedDegreeId
    );
    

    编辑:或者这个。

    repo.DeleteMany(x =>
        x.MeetingAttendeeUserId == userID &&
        userDegreeList.Contains(x.EducationDegreeID))
    );
    

    【讨论】:

      【解决方案2】:

      我试过了

      SubSonicRepository<ReportDatum> repo = new SubSonicRepository<ReportDatum>(db);
      repo.DeleteMany(x => x.ReportID == Convert.ToInt32(reportID));
      

      它什么也不做,甚至没有错误。

      遇到此问题的人的附录: 不要在删除调用中进行转换,请事先转换您的变量。

      int deleteKey = Convert.ToInt32(reportID)
      SubSonicRepository<ReportDatum> repo = new SubSonicRepository<ReportDatum>(db);
      repo.DeleteMany(x => x.ReportID == deleteKey);
      

      它发射得很好。

      【讨论】:

        【解决方案3】:

        如果您不知道 Lamda 表达式,我会推荐。创建您自己的存储过程并调用使用它。

        如果您没有时间学习,这不会限制您使用 lamda 表达式。

        最终你想完成你的工作。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-06-10
          • 1970-01-01
          相关资源
          最近更新 更多