views:

44

answers:

1

For instance, if I want to map property Title I use:

> Map(x => x.Title);

That's weird because this delegate is only returning the value of the property and not the property itself while NHibernate needs to know the property itself.

How does it work?

+3  A: 

Map is a function, that (among other things via overloads) takes a Expression<Func<T>> - i.e. it looks like a Func<T>, but Expression<Func<T>> gets converted into an expression tree instead of just the lambda.

Expression trees are basically ASTs, and you can write code to traverse an expression tree to extract a string with the property name, allowing you to reflect "normally" from then on.

There's a lot of stuff available where people write stuff that reflect on expression trees. Check out this post for example, for a demonstration on how to write a couple of utility methods to make the reflection easy.

mookid8000
Thank you mookid. I'm gonna look at Expression Trees to understand it better.
Ciwee