Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fluent NHibernate many to many convention for type

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

like image 804
Andrew Bullock Avatar asked Feb 13 '09 15:02

Andrew Bullock


1 Answers

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.

like image 130
James Gregory Avatar answered Oct 12 '22 05:10

James Gregory