我是linq的新手,我想知道如何在linq查询中编写不等于(!=),如SQL中所示:
select
projects.Name
from
Projects
inner join
projectPermissions on (projects.FK_Owner_ID != projectpermissions.FK_User_ID and Projects.Project_ID = projectPermissions.FK_Project_ID)
where
ProjectPermissions.FK_User_ID = 53;
var projects = (from project in this.context.Projects
join shareProjects in this.context.ProjectPermissions on
new { UserID = project.FK_Owner_ID, ProjectID = project.Project_ID } equals
new { UserID = shareProjects.FK_User_ID, ProjectID = shareProjects.FK_Project_ID }
where shareProjects.FK_User_ID == userId
select new
{};
您可以始终使用where
代替,join只支持相等键比较:
var projects =from project in this.context.Projects
join shareProjects in this.context.ProjectPermissions on
project.Project_ID equals shareProjects.FK_Project_ID
where project.FK_Owner_ID != shareProjects.FK_User_ID &&
shareProjects.FK_User_ID == userId
select new{};
你必须否定它:
on (!(projects.FK_Owner_ID == projectpermissions.FK_User_ID) and Projects.Project_ID = projectPermissions.FK_Project_ID)