7
votes

Im using the AutoPersistenceModel in Fluent NHIbernate to map all my entities and that all works fine :D

However, several of my objects have

public virtual IList<Comment> Comments { get; set; }

In the database there is a single comments table, and each entity with the above code, has its own link table to comments.

At the moment what im doing is:

public class ContractMappingOverride : IAutoMappingOverride<Contract>
{
    public void Override(AutoMap<Contract> mapping)
    {
        mapping.HasManyToMany(x => x.Comments)
            .WithTableName("Comment_Contract");

for every entity.

Is there some way i can set a convention where by all mappings to IList<Comment> are wired up automatically as manytomany with the above table name convention?

Thanks

Andrew

2

2 Answers

5
votes

I know it's not what you want to hear, but the answer is no.

In the current design of Fluent NHibernate, there isn't a way to apply conventions to collections while having knowledge of the types they're being used in, you can apply something to all collections just not depending on their contained type. This is a flaw in our design and I aim to correct this, but it is quite a large change so it won't be happening overnight.

I'd recommend you check in with our mailing list, we usually post updates there.

Sorry I can't be more helpful.

0
votes

It's been a while since I've worked with the Fluent NHibernate and am just currently getting back into the swing of it (wow there's been alot of changes since early 09!) and I think the answer to your question now is yes you can do this with the OverideAll functionality.

Take a look at Overrides on the FNH wiki.