Please consider the following simple use case:
public class Foo
{
public virtual int Id { get; protected set; }
public virtual IBar Bar { get; set; }
I haven't tried this myself but i saw an example in the fluent nh source where the lambda is cast to the concrete class:
public class FooMap : ClassMap
{
public FooMap()
{
Id(x => x.Id);
Component(x => (Bar) x.Bar, m =>
{
m.Map(x => x.Text);
});
}
}
EDIT: Obviously that's exactly the same result as Sly's suggestion so that did no good. I tested it against the trunk version of fluent nh and it didn't work. It does work though if you use a many-to-one mapping:
public class FooMap : ClassMap
{
public FooMap()
{
Id(x => x.Id);
References(x => x.Bar).Cascade.All();
}
}
public class BarMap : ClassMap
{
public BarMap()
{
Id(x => x.Id);
Map(x => x.Text);
}
}
UPDATE
This was actually an easy fix. I have submitted a patch (link text) that makes Sly's solution to work.