I'm still a little new to Linq-To-SQL and I'm having a problem when I try to use the join operator (doing the equivalent of an SQL inner join).
Get all the preferences for a user:
return (from u in DataContext.UserPreference
join p in DataContext.Preference on p.Id equals u.PreferenceId
where u.UserId = userId
select p).ToList();
Visual Studio tells me that the "join" operator in the query is an "ambiguous call" between the Enumerable class and the Queryable class.
Any ideas how I can resolve this?
Your join is expressed the wrong way round - you should be using u first, then p:
return (from u in DataContext.UserPreference
join p in DataContext.Preference on u.PreferenceId equals p.Id
where u.UserId == userId
select p).ToList();
Basically you use the first range variable on the left side of the join, and the second variable on the right side.
Usually this sort of error is spotted by the compiler which suggests exactly what's wrong. I don't know why it didn't in this case, but either way the above should be the fix.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With