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