views:

27

answers:

1

I'm currently using a convention to (auto)map collection properties to backing fields in Fluent NHibernate. So, I map a property "Orders" to a field "_orders". The convention I'm using to do this is:

public class HasManyAccessConvention : IHasManyConvention
{
    public void Apply(IOneToManyCollectionInstance instance)
    {
        instance.Access.CamelCaseField(CamelCasePrefix.Underscore);
    }
}

The kind of class I'd be trying to map with a new convention is:

public class Customer
{
    public virtual IEnumerable<Order> Orders
    {
        get
        {
            return xyz_orders;
        }
    }

    private readonly IList<Order> xyz_orders = new List<Order>();
}

Can I write a convention that maps a (collection) property to a field with a non-standard prefix (ignoring whether this is good coding practice for the present)? So, the property "Orders" would be mapped to "xyz_orders", for example.

If so, how would I go about this?

A: 
instance.Key.Column("xyz_" + instance.ForeignKey);

Is that what you meant?

HeavyWave
That doesn't seem to work. instance.EntityType.Name is the name of the class containing the property, I'm trying to map, for example. So it would be "Customer" (type), instead of "Orders" (property).
dommer
I have updated it to use the foreignkey you have specified and add a prefix to it. Just play around with instace.
HeavyWave
I can get at the property name with "instance.Member.Name" (which I'll then have to camel case, but I can hack that for now). But setting instance.Key.Column doesn't seem to map the property to the field. The configuration code complains about "Orders" not having a setter (i.e. it doesn't know it's supposed to map to the xyz_orders field).
dommer

related questions