I’m having troubles with this ternary line:
var userFromContext = IsOwner ? db.Owners.Where(o => o.UserName == username)
: db.Users.Where(u => u.UserName == username);
It’s giving me this error message:
Type of conditional expression cannot be determined because there is no implicit conversion between System.LINQ.IQueryable<Owners> and System.LINQ.IQueryable<Users>.
Why should it care if I’m assigning it to a var variable?
Because the variable has to be of some type.
“
var” doesn’t mean “untyped“. It means “dear compiler, please figure out what the type of this variable should be based on the expression that I’m assigning to it“.In order to do that, the compiler must first understand what the type of expression is, and it can’t do that because two branches of your ternary operator are of different types.