0
我有一個tolist方法,使數據庫裏面的變化,但我想計數多少次我的Where子句是真的。 Tolist的作品如何添加一個計數..mvc3我怎麼能包括一個Tolist裏面的Count方法
// the count to see how many times getid== x.RegistrationID
List<Article> getprofile = (from x in db.Articles where getid == x.RegistrationID select x).ToList();
foreach (var items in getprofile)
{
items.articlecount = items.articlecount + 1;
db.Entry(items).State = EntityState.Modified;
db.SaveChanges();
}
看起來像getprofile.count會給你這個答案。但我懷疑,如果這很容易,你不需要發表Q.所以請進一步澄清。 – 2013-02-10 16:55:31
getprofile.count不能用於foreach ..基本上,「articlecount」是數據庫中的INT字段,它的唯一目的是保持計算用戶創建的文章數量,當您創建新文章Articlecount應該增加+1。我使用.tolist和foreach來更新GetProfile True的所有文章的「articlecount」。 – user1949387 2013-02-10 18:16:08