This project is read-only.

Help with subclass mappings

Jan 19, 2015 at 3:28 PM
Edited Jan 19, 2015 at 3:31 PM
Hi, I've created a BaseUser class which contains pretty much all info I need and then I've made subclasses for BaseUser for managing location of these users. So I have ExternalUser (CN=External, CN=Users ....) and InternalUser (CN=Internal, cn=users...). It was all mapped with AttributeClass Mapping
It was working beautiful but then I had problems with datetime format so I ended up moving all mappings to a Class Map Mapping.

How can I make my subclasses take the mapping I define in my base class?

Here's how I had it before
[DirectorySchema("CN=Users,cn=dsdffs,dc=sddf,dc=com",ObjectCategory = "Person", ObjectClass = "User")]
public class BaseUser
{
       [DirectoryAttribute("cn", ReadOnly = true)]
       public string UserName{ get; set; }

        [DirectoryAttribute("givenName")]
        public string Name{ get; set; }

       // and so on

}

 [DirectorySchema("CN=External,CN=Users,cn=sdsd,dc=sds,dc=com", ObjectClass = "User")]
public class ExternalUser : BaseUser
{
    // some specific property for external users
}
and in my global.asax
config.AddMapping(new AttributeClassMap<InternalLdsUser>())
                    .AddMapping(new AttributeClassMap<ExternalLdsUser>())
                    .AddMapping(new AttributeClassMap<BaseUser>())
This worked like I've expected, but then I had issues with DateTime conversions so (after reading your examples) I moved all to Class Mapping
public class BaseUserMap : ClassMap<BaseUser>
    {
       
        public override IClassMap PerformMapping(string namingContext = null, string objectCategory = null, bool includeObjectCategory = true,
            IEnumerable<string> objectClasses = null, bool includeObjectClasses = true)
        {
            NamingContext("CN=Users,cn=ssds,dc=sdfs,dc=com");

        ObjectCategory("Person");
        ObjectClass("User");

        DistinguishedName(x => x.Dn);
        Map(x => x.AccountExpires).Named("accountExpires").DateTimeFormat(null).StoreGenerated()
                 .DirectoryValue("9223372036854775807").Returns(null)
                 .InstanceValue(DateTime.MinValue).Sends("9223372036854775807")
                 .InstanceValueNullOrDefault().Sends("9223372036854775807");
Map(x => x.UserName).Named("cn").ReadOnly();
            Map(x => x.Name).Named("givenname");
return this;
what should I put in
public class ExternalUserMap : ClassMap<ExternalUser>
    {
       
        public override IClassMap PerformMapping(string namingContext = null, string objectCategory = null, bool includeObjectCategory = true,
            IEnumerable<string> objectClasses = null, bool includeObjectClasses = true)
        {
            NamingContext("cn=External,CN=Users,cn=ssds,dc=sdfs,dc=com");

        ObjectCategory("Person");
        ObjectClass("User");
}
}
so it takes also the mappings from BaseUser ?

Thanks!
German
Jan 23, 2015 at 2:30 PM
Nevermind, I've read the docs! :-)

Man, this tool is awesome!! Congrats again to MadHatter!

German
Marked as answer by germansak on 1/23/2015 at 6:38 AM