StartsWith errors if using a parameter

Jun 13, 2008 at 2:15 PM
Edited Jun 13, 2008 at 2:29 PM


First, this library a great idea and really appreciated.

We were attempting to create an autocomplete textbox and were trying to use the StartsWith LINQ operator:
public static List<Group> GetGroups(string startsWith)

if (String.IsNullOrEmpty(startsWith)) throw new ArgumentException("startsWith cannot be null or empty."); 

var ADGroups = new DirectorySource<Group>(Config.LDAPDirectoryEntry, SearchScope.Subtree); 

var groups = ADGroups.Where(g => g.Name.StartsWith(startsWith)).Select(c => new Client { Name = g.Name, DateCreated = g.DateCreated, DateUpdated = g.DateUpdated });

return groups.ToList();


However, when passing the StartsWith parameter as a parameter the string somehow gets passed as a property of an object within DirectoryQuery...
ConstantExpression c = m.Arguments[0] as ConstantExpression;

Where c.Value would normally contain the string passed as the parameter it now is c.Value.startsWith (being that I named the parameter as startsWith).

I tried debugging and correcting this, and also tried using reflection to dynamically access the property on c.Value, but I am unable figure this one out.  Any ideas?


Jul 1, 2008 at 9:57 PM
This is a known issue.  Use the remedy disussed here