Using AD filters?

Jun 28, 2013 at 7:10 PM
I would like to use the following AD filter in my query - how would I specify this as part of the linq query?

"(&(objectCategory=person)(objectClass=user)(|(accountExpires>=$today)(accountExpires=0)))"
Coordinator
Jun 28, 2013 at 9:44 PM
Hi Morgant,

First of all, thanks for using the framework. The following code will get you the result you are looking for.
    [DirectoryType("User")]
    public class User : UserEntryObject
    {
        private long _accountExpires;

        [DirectoryProperty("accountExpires")]
        public long AccountExpires
        {
            get
            {
                return _accountExpires;
            }
            set
            {
                if (_accountExpires != value)
                {
                    _accountExpires = value;
                    NotifyPropertyChanged("AccountExpires");
                }
            }
        }
    }

    [TestMethod]
    public void WhereAccountExpiresTodayOrLaterOrIsZeroTest()
    {
        using (var context = new DirectoryContextMock())
        {
            var users = context.Users.Where(u => u.AccountExpires >= DateTime.Today.ToFileTime() || u.AccountExpires == 0);
            Assert.AreEqual(users.Count(), 7);
        }
    }
Thanks,
Stephen Baker
Marked as answer by sbaker on 10/7/2013 at 9:43 AM