0

I'd like to parse through an Fluent NHibernate mapping file so I can get the table name and column names that are specified in there.

Loading the assembly and reflecting the type as ClassMap isn't a problem but that class only get methods to set the table and column names - nothing to get the names back again.

Any ideas?

johnnyboy
  • 869
  • 12
  • 23

1 Answers1

0

Using Reflector, it looks like Table method has this signature:

public void Table(string tableName)
{
    this.attributes.Set<string>(x => x.TableName, tableName);
}

Columns will be a lot harder as it keeps properties, references, and collections separate. Eg.

protected virtual PropertyPart Map(PropertyInfo property, string columnName)
{
    PropertyPart propertyMap = new PropertyPart(property, typeof(T));
    if (!string.IsNullOrEmpty(columnName))
    {
        propertyMap.Column(columnName);
    }
    this.properties.Add(propertyMap);
    return propertyMap;
}

In theory though you could get the private fields attributes, properties, and references via reflection and get the information that way.

Vadim
  • 17,897
  • 4
  • 38
  • 62
  • Turns out I didn't need this as much as I thought. Apparently the CreateQuery method in nHibernate parses the string with the object name and maps the class field names to column names for you - still learning nhibernate :\ I've ended up writing my own Update method which takes a list of lambda expressions of fields to update and the new values and a list of lambda expressions for the conditional clause rather than using nHibernate to load each entity for each update. – johnnyboy Feb 02 '11 at 04:10