1. 程式人生 > >entity framework 刪除多條資料?

entity framework 刪除多條資料?

根據某個id刪除資料

應為根據這個id會搜出多條資料比如下面的 linq to entity語句得到多個結果

var query=(from comment in db.comments where comment.blog_id == id select comment);

刪除的時候怎麼樣才可以一口氣 一次性的刪除掉所有資料而不是通過迴圈一條條刪呢?

還有如果

1 foreachvar i in query)  //這樣是不是會因為延遲查詢的原因 而出現效能問題
2 
3 {
4 // 刪除語句
5 }
public int DeleteAllcomment(int blog_id

        { 
            return entities.ExecuteStoreCommand("delete from comment where blog_id= @blog_id", new SqlParameter("@blog_id",blog_id)); 
        }