I do not believe you can through linq. The following are the limitations of the where clause of the SDK.
where => The left side of the sentence should be the name of the attribute, and the right side of the sentence should be the value. You cannot set the left side to constant. Both sides of a sentence cannot be constants.
Supports String functions Contains, StartsWith, EndsWith and Equals.
You can get around these limitations using QueryExpression or FetchExpressions. The query you want will look like this using QueryExpression. The only thing I would like to mention is that if you expect a lot of entries (in my opinion, 5000+), you will most likely need to implement swap for your function.
private static IEnumerable<Account> GetAccounts(IOrganizationService proxy) { List<String> accountIds = new List<String>(new string[]{"654321", "12345"}); var results = proxy.RetrieveMultiple(new QueryExpression(Account.EntityLogicalName) { ColumnSet = new ColumnSet("accountid", "name", "accountnumber"), Criteria = new FilterExpression() { Conditions = { new ConditionExpression("accountnumber", ConditionOperator.NotIn, accountIds) } } }); return results.Entities.Select(x=> x.ToEntity<Account>()); }
source share