var exercises = _repository.Exercises.Where(a =>
userPrincipal.User != null && // false
(
userPrincipal.Activated && a.PrivacyString == Privacy.PUBLIC_TO_REGISTERED_USERS.ToString() ||
userPrincipal.User.Id == a.User.Id && a.PrivacyString == Privacy.PRIVATE.ToString()
)
).ToList();
This is my code, this should never go beyond from false, but it is running into the bottom clause also. There was basically a null check, but now EF is giving me nullpointer error
{"Non-static method requires a target."}
When I remove userPrincipal.User.Id
from the query, then I do not get exception, so I know that userPrincipal.User
is null.
EDIT:
_repository definition.
public DbSet<Exercise> Exercises { get; set; }
IQueryable<Exercise> IRepository.Exercises {
get { return Exercises; }
}
EDIT: query generated by EF.
SELECT
1 AS [C1],
CAST(NULL AS int) AS [C2],
CAST(NULL AS varchar(1)) AS [C3],
CAST(NULL AS varchar(1)) AS [C4],
CAST(NULL AS varchar(1)) AS [C5],
CAST(NULL AS varchar(1)) AS [C6],
CAST(NULL AS varchar(1)) AS [C7],
CAST(NULL AS int) AS [C8]
FROM ( SELECT 1 AS X ) AS [SingleRowTable1]
WHERE 1 = 0