这里有一个小LinqToSql疑难杂症:条件的快捷方式
// Returns the number of counties in a state,
// or all counties in the USA if the state is null
public static int CountCounties(State s) {
var q =
from cy in County.GetTable() // my method to get the ITable
where (s == null || s.Code == cy.StateCode) // shortcut OR operator, right...?
select cy;
return q.Count();
}
你猜怎么着 - 如果你传递一个空State
对象这种方法,你会得到一个空引用异常!看来LinqToSql并不使用||
快捷键作为快捷键!
回答信贷去谁建议最好的解释&解决方法为此。
这是LinqToSql? – 2009-12-06 11:26:31
在'正常'Linq类似的查询适合我。 – 2009-12-06 11:57:25
是的,这是LinqToSql - 对不起,将编辑的问题 – 2009-12-06 12:07:51