Reputation: 62886
I have the following code:
var tfs = new TfsTeamProjectCollection(new Uri(TFS_SERVER_URL));
tfs.EnsureAuthenticated();
var query = GetQuery(...)
var identities = ims.ReadFilteredIdentities(query, 5000, null, true, (int)MembershipQuery.None);
foreach (var item in identities.Items)
{
Console.WriteLine("{0,-20} {1,-20} {2}", item.DisplayName, item.UniqueName, item.GetAttribute("Mail", null));
}
Now, when query is something like
Microsoft.TeamFoundation.Identity.Type == 'User' AND (Microsoft.TeamFoundation.Identity.DisplayName CONTAINS 'alice' OR Microsoft.TeamFoundation.Identity.DisplayName CONTAINS 'bob')
The code throws the following exception:
Microsoft.TeamFoundation.Framework.Client.IdentityExpressionException: TF400819: Query Expression is not well-formed
---> System.Web.Services.Protocols.SoapException: TF400819: Query Expression is not well-formed
--- End of inner exception stack trace ---
at Microsoft.TeamFoundation.Client.Channels.TfsHttpClientBase.HandleReply(TfsClientOperation operation, TfsMessage message, Object[]& outputs)
at Microsoft.TeamFoundation.Client.Channels.TfsHttpClientBase.Invoke(TfsClientOperation operation, Object[] parameters, TimeSpan timeout, Object[]& outputs)
at Microsoft.TeamFoundation.Framework.Client.IdentityManagementWebService2.ReadFilteredIdentities(String expression, Int32 suggestedPageSize, String lastSearchResult, Boolean lo
okForward, Int32 queryMembership, Int32 features)
at Microsoft.TeamFoundation.Framework.Client.IdentityManagementService2.ReadFilteredIdentities(String expression, Int32 suggestedPageSize, String lastSearchResult, Boolean lookF
orward, Int32 queryMembership)
at TFSTool.Program.GetUsers(IEnumerable`1 args) in C:\dayforce\SharpTop\Build\ConfigurationManagement\utilities\tfstool\Program.cs:line 1621
at TFSTool.Program.Main(String[] args) in C:\dayforce\SharpTop\Build\ConfigurationManagement\utilities\tfstool\Program.cs:line 519
However, if I search by just one user pattern, for example:
Microsoft.TeamFoundation.Identity.Type == 'User' AND Microsoft.TeamFoundation.Identity.DisplayName CONTAINS 'mark'
It works just fine.
So, my question - is it possible to search by more than one user pattern in TFS Api or am I forced to repeat the query for each pattern separately?
Upvotes: 0
Views: 130
Reputation: 29976
No, you can't. "OR" operator is not supported by the query expression. Refer to the description for ReadFilteredIdentities() method in this article for details: TeamFoundationIdentityService Class.
ReadFilteredIdentities is used to retrieve a set of identities based on an expression. The expression is a syntax that resembles a SQL WHERE clause. For details about the expressions capabilities, see the documentation of the QueryExpression class. There are two parts to the expression. There are a set of values that can be used from the identity and they must be AND'ed together.
Upvotes: 1