zoukankan      html  css  js  c++  java
  • linqef中如何批量删除

    1、首先在数据库中建立函数

    CREATE   FUNCTION [dbo].[Split]  
    (  
    @c VARCHAR(MAX) ,  
    @split VARCHAR(50)  
    )  
    RETURNS @t TABLE ( col VARCHAR(50) )  
    AS  
    BEGIN  
        WHILE ( CHARINDEX(@split, @c) <> 0 )  
            BEGIN  
                INSERT  @t( col )  
                VALUES  ( SUBSTRING(@c, 1, CHARINDEX(@split, @c) - 1) )  
                SET @c = STUFF(@c, 1, CHARINDEX(@split, @c), '')  
            END  
        INSERT  @t( col ) VALUES  ( @c )  
        RETURN  
    END  

    2、再建立存储过程

    USE [iLearning]
    GO
    
    /****** Object:  StoredProcedure [dbo].[usp_delete_courses]    Script Date: 04/26/2013 13:52:56 ******/
    SET ANSI_NULLS ON
    GO
    
    SET QUOTED_IDENTIFIER ON
    GO
    
    
    create proc [dbo].[usp_delete_courses]
    @ids varchar(max)
    as  
    update t_course_addition set isactive='N',updatetime=getdate() where id in (select * from Split(@ids,','));
    update t_course_comment set isactive='N',updatetime=getdate() where courseid in (select * from Split(@ids,','));
    update t_course_previewimage set isactive='N',updatetime=getdate() where courseid in (select * from Split(@ids,','));
    update t_course set isactive='N',updatetime=getdate() where id in (select * from Split(@ids , ','));
    
    GO

    3、最后,在DAL中调用:

    var objectParm = new[] { new ObjectParameter("ids", deleteIdStr) };
                        return db.ExecuteFunction("iLearningEntities.usp_delete_courses", objectParm);
  • 相关阅读:
    sql server 查询数据判断为空
    sql 排序
    ASP.NE 上传文件控件
    JQ 获取下一个元素和获取下一个元素的[指定]子元素
    sql server 查询时间 格式化输出
    ASP.NET 页面验证cookie
    ASP.NET MD5加密
    HTML编辑器ASP.NET
    Repeater控件
    20150215-情愿
  • 原文地址:https://www.cnblogs.com/Benjamin/p/3044707.html
Copyright © 2011-2022 走看看