There are 2 ways to achieve this:
Using where with multiple OR statements (i.e. WorkItem = id-1 OR WorkItem = id-2 .. etc).
Using IN with query.
The second option will only work if you can get the list of Work Item IDs using a subquery
What is the right way to perform query by multiple Ids.
For example get entity "ResourceLink" where WorkItem filed
equals "id-1" or "id-2"…or "id-n".
Like sql "in"
statement.
Thanks
Please sign in to leave a comment.
There are 2 ways to achieve this:
Using where with multiple OR statements (i.e. WorkItem = id-1 OR WorkItem = id-2 .. etc).
Using IN with query.
The second option will only work if you can get the list of Work Item IDs using a subquery
Can you give a sample code for the 2. option: "IN" statement
Thanks
I'll give examples for the 2 options.
Option1: Let's assume you have 3 IDs of users, and you want to find all the tasks that are managed by one of those users. The query you'd want to perform is something like:
SELECT Name FROM Tasks Where Manager=1 OR Manager=2 OR Manager =3
If we translate it to C# it would look something like this:
For the 2nd Option:
Let's assume you want to find the tasks that are managed by users who's name starts with "A".
The SQL would look something like this:
SELECT Name FROM Tasks Where Manager IN (SELECT ID FROM Users Where Username LIKE "A%")
If we translate it to C# it would look something like this:
Hello,
Could you advice me please, how query like
SELECT DisplayName FROM Users WHERE id in( SELECT ... ) will look like?
Which field should i specify for LeftExpression in this case?
(I need to select users which belongs to some set of groups)
Thank you
Hi Oleg. If you have the list of IDs and this is the only filter, why not use RetrieveMultipleMessage instead?
If you need to use a Query condition though, specify EntityIdExpression on the left expression (EntityIdExpression has no properties),
Equal on the operator and a _ConstantExpression _containing just the Id in the right expression
Sample:
Where =new Compare
{
LeftExpression=new EntityIdExpression(),
Operator = Operator.Equal ,
RightExpression =new ConstantExpression(){Value=projectId.Value}
}
Obviously, you have to create several of these and wrap them with an Or condition.
Hope this helps
Thank you again, Ophir!