I was able to add a dynamic-component and populate that component with the 
correct properties at runtime by using the following link as a starting 
point.

http://www.junasoftware.com/blog/custom-domain-using-nhibernate-dynamic-component.aspx
 

You can still use the by code configuration to setup your dynamic 
component. Notice the anonymous type has no properties (because they are 
not known). 

    mapper.Class<Test>(map =>

         {
            map.Component("DynamicAttributes", new { },componentMap =>
            {
               componentMap.Access(Accessor.NoSetter); // I do not have a 
setter
            });
            

         });


After you add your mappings to the Configuration, add the code seen in 
AddMappingExtensions (from the link). You'll have to modify it based on how 
you get your dynamic attribute metadata. 

Example:

         foreach (var classMapping in config.ClassMappings)
         {
            // only do this for the class named Test for testing...
            if (classMapping.EntityName != "YourCoolNamepsace.Test")
            {
               continue;
            }
            var componentProperty = 
classMapping.GetProperty("DynamicAttributes");
            var component = (Component)componentProperty.Value;
 
            //foreach (TODO: get user defined attributes from somewhere)
            {               

               // CreateDynamicProperty is hard coded to work with string for 
testing...

               
component.AddProperty(CreateDynamicProperty("SomeDynamicAttribute", 
classMapping));

               component.AddProperty(CreateDynamicProperty(
"SomeOtherDynamicAttribute", classMapping));             }          }



-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/nhusers/-/sSVuAkGOpawJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to