I have a table Site
in SQL with (amongst others) three properties idReviewer1
, idReviewer2
, idReviewer3
. Now I would like to create a methods on the entity class of Site to check if a user is a reviewer:
partial class Site
{
public bool IsReviewer(int idUser)
{
return idReviewer1 == idUser || idReviewer2 == idUser || idReviewer3 == idUser;
}
}
and I use it like this:
return from s in db.Sites
where s.IsReviewer(user)
select s;
However, Linq to SQL doesn't know how to translate this to SQL. I get the following error message:
Method 'Boolean IsReviewer(Int32)' has no supported translation to SQL.
I'd rather not write this:
return from s in db.Sites
where idReviewer1 == idUser || idReviewer2 == idUser || idReviewer3 == idUser
select s;
Is there any way to put this functionality in one place, without resorting to SQL?