我想获得下面的linq查询返回-1
如果没有任何当前值。我在MSDN上看到这篇文章,here,它似乎DefaultIfEmpty()
是我想要的。LINQ DefaultIfEmpty(),生成推断的参数错误
不幸的是,我得到一个The type arguments cannot be inferred from the usage. Try specifying the type arguments explicitly.
错误。
我想我不确定这意味着什么或它告诉我要做什么。请有人解释一下。
public static int CheckForDRIID(int personID)
{
using (var context = ConnectDataContext.Create())
{
var masterIndex =
(from applicationAssociation in context.tblApplicationAssociations
where applicationAssociation.ApplicationID == 1 && applicationAssociation.PersonID == personID
select applicationAssociation.PersonApplicationID).DefaultIfEmpty(-1).Single();
return Convert.ToInt32(masterIndex);
}
}
'applicationAssociation.PersonApplicationID'是什么类型?它是一个'int'还是一个可空的? –
2010-04-21 16:44:59
'PersonApplicationID'是一个'string' – 2010-04-21 16:46:29
为什么你会在一个字符串中存储一个ID?错误的数据库设计,你不能改变? – 2010-04-21 17:10:46