LINQ DefaultIfEmpty(), generating inferred argument error
Posted
by Refracted Paladin
on Stack Overflow
See other posts from Stack Overflow
or by Refracted Paladin
Published on 2010-04-21T16:40:08Z
Indexed on
2010/04/21
16:43 UTC
Read the original article
Hit count: 324
I am trying to get the below linq query to return -1
if there isn't any current value. I was looking at this article on MSDN, here, and it seemed that DefaultIfEmpty()
was what I wanted.
Unfortunately, I am getting a The type arguments cannot be inferred from the usage. Try specifying the type arguments explicitly.
error.
I guess I am not sure what that means or what it is telling me to do. Can someone explain, please.
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);
}
}
© Stack Overflow or respective owner