【发布时间】:2011-01-18 20:06:26
【问题描述】:
我最初将此作为对this question 的回复发布,但我意识到我应该问一个新的。这似乎表明我应该能够做到以下几点:
int count = Db.Countries.Count();
Country newCountry = new Country{Name = "France"};
Db.Countries.InsertOnSubmit(c);
Country getCountry = Db.Countries.FirstOrDefault(x => x.Name == "France");
count = Db.Countries.Count();
Db.Countries.DeleteOnSubmit(c);
count = Db.Countries.Count();
但是,在空表上,count 在调试器中单步执行时始终保持为0,而在执行后getCountry 为null。
我错过了什么?
【问题讨论】:
-
这有点离题了,但是那些 Count() 操作非常繁重吗?我知道它使数据库查询来计算行数。也许将其转换为列表,然后在 Count() 上取 Count 更快?
-
Count()比转换为列表然后计算其中的对象要快。select count(1) from Country总是比select x, y, z from Country快,然后计算结果。
标签: .net linq-to-sql