0

I wrote a little console app that is supposed to write out properties for a given class.

It works on "normal" classes, but it just shows a blank list when I try and pass in a NHibernate classMapping class.

Stepping through the debugger in Visual Studio, I just see empty values and one, non-show stopping error: "No further information on this object could be discovered."

Is there a way to get the parameters/properties used in a ClassMapping class?

Thanks!

Mapping class:

public class CorporateDataMapping : ClassMapping<CorporateData>
{
    public CorporateDataMapping()
    {
        Schema("data");
        this.EnhancedSequenceId(x => x.Id);
        ManyToOne(x => x.CEO, pm => pm.NotNullable(true));
        Property(x => x.Sign, pm => pm.NotNullable(true));
        Property(x => x.WeatherType, pm => pm.NotNullable(true));
        Property(x => x.EncodingLanguage);
        Property(x => x.ZipCode);
        Property(x => x.PhysicalLocation);
        Property(x => x.Extension, pm => pm.NotNullable(true));
        Property(x => x.DisplayAllYear, pm => pm.NotNullable(true));
    Property(x => x.Graphics, pm => pm.NotNullable(true));
        Property(x => x.InstallDate, pm => pm.NotNullable(true));
    }
}

Program that is suppposed to display all properties of the class:

    static void Main(string[] args)
    {
        CorporateDataMapping mapping = new CorporateDataMapping();
        printProperties(mapping);

        Console.ReadLine();
    }

    public static void printProperties(Object jsonObject)
    {
        JObject json = JObject.FromObject(jsonObject);
        Console.WriteLine("Classname: {0}\n", jsonObject.ToString());
        Console.WriteLine("{0,-20} {1,5}\n", "Name", "Value");
        foreach (JProperty property in json.Properties()) { 
            Console.WriteLine("{0,-20} {1,5:N1}",  property.Name, property.Value);
        }
    }
}
SkyeBoniwell
  • 6,345
  • 12
  • 81
  • 185

1 Answers1

1

The properties of the mapped class do not become part of mapper, hence they cannot be fetched by reflection on mapper class. Read up on the class ModelMapper NHibernate. Some uses are shown in following links (you can find more by googling "nhibernate modelmapper beforemapproperty"):

http://nhibernate.info/blog/2011/09/04/using-nh3-2-mapping-by-code-for-automatic-mapping.html

Nhibernate : Map all decimals with the same precision and scale

Community
  • 1
  • 1
Vijay Gill
  • 1,508
  • 1
  • 14
  • 16