Add

Adding an entry can be accomplished either with a mapped class or the DirectoryAttributes class. To add an entry you must specify an objectClass. For mapped classes it must be done at mapping. For DirectoryAttributes it can be done before adding the entry.
Mapped Class
var role = new Role();
role.Member = new Collection<string>();
role.Member.Add("CN=Test User,CN=Users,DC=example,DC=com");
role.DistinguishedName = 
     "CN=Test Role,CN=Roles,DC=example,DC=com";

//will assume there is a mapped object class or object category.  
//If there isn't one then the directory will most likely throw an exception, 
//but each server may behave differently.
var added = _context.Add(role);

Directory Attributes
var attributes = 
     new DirectoryAttributes("CN=Test Role,CN=Roles,DC=example,DC=com");
attributes.Set("member", 
     new [] { "CN=Test User,CN=Users,DC=example,DC=com" });
attributes.Set("objectclass", "group");

var added = context.Add(attributes);

Last edited Oct 28, 2012 at 2:53 AM by MadHatter22, version 4