I want to choose a record that is not in the database.
var context = new PrincipalContext(ContextType.Domain); var searcher = new PrincipalSearcher(new UserPrincipal(context)); string objectGUID; foreach (var result in searcher.FindAll()) { DirectoryEntry de = result.GetUnderlyingObject() as DirectoryEntry; Guid _guid = new Guid((byte[])(Array)de.Properties["objectGUID"][0]); objectGUID = _guid.ToString(); var test = db.ADUsers.Where(a => a.ObjectGUID != objectGUID).FirstOrDefault(); } I take objectGUID from Active Directory as a kind of unique number and want to compare it with objectGUID in the database and if there is no such objectGUID in the database, then write it there.
I do like this a.ObjectGUID == objectGUID and in the console everything is OK, I get the whole list by coincidence.
var test = db.ADUsers.Where(a => a.ObjectGUID == objectGUID).FirstOrDefault(); But is it logical to do a.ObjectGUID != objectGUID and get data that is not in the table? But this method does not work. Help!