[英]How to use <> expression in Entity Framework
We need to convert following query to Entity framework syntax based query but not fond any alternative for '<>' condition:我们需要将以下查询转换为基于实体框架语法的查询,但不喜欢 '<>' 条件的任何替代方案:
Query:询问:
select (FirstName+' '+LastName) AS Name ,WorksNumber from [TSHumanResource]
join [TSUserProfile] on [TSUserProfile].[TSPersonID] = [TSHumanResource].[TSPersonID]
join [TSPerson] on [TSPerson].[TSPersonID] = [TSHumanResource].[TSPersonID]
where [TSUserProfile].[TSUserStatusID] = 1
and [EmployeeReference] <> ' ' and [MMSUserID] is not null order by [WorksNumber] asc
Here's what I was tring:这是我正在尝试的内容:
(from HR in oDB.TSHumanResources
join UP in oDB.TSUserProfiles on HR.TSPersonID equals UP.TSPersonID
join P in oDB.TSPersons on HR.TSPersonID equals P.TSPersonID
where UP.TSUserStatusID == 1 && HR.EmployeeReference <>
select new
{
ID = e.TSPersonID ,
ID = e.TID,
}).Take(10);
The SQL Server operator <>
means not equal . SQL Server 运算符
<>
表示不等于。 In c#, the not equal operator is written like this: !=
.在 C# 中,不等于运算符的写法如下:
!=
。
You have another problem in your linq query - you are currently doing an inner join instead of a left join .您的 linq 查询中还有另一个问题 - 您目前正在执行内部联接而不是左联接。
A left join in LINQ is a bit cumbersome comparing to a left join in SQL - it has to go through a group join first.与 SQL 中的左连接相比,LINQ 中的左连接有点麻烦——它必须先通过组连接。 Your query should look more like this:
您的查询应该更像这样:
from hr in TSHumanResource
join up in TSUserProfile on hr.TSPersonID equals up.TSPersonID into upgroup
from upg in upgroup.DefaultIfEmpty()
join p in TSPerson on upg.TSPersonID equals p.TSPersonID into pgroup
from puphr in pgroup.DefaultIfEmpty()
where up.TSUserStatusID = 1
&& HR.EmployeeReference != " " // Assuming you want it different than a single space
// Other conditions here - I don't know where MMSUserID belongs to
order by hr.WorksNumber // just guessing here - I don't know if it's from hr
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.