views:

1229

answers:

4

Hi,

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  A: 

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.

James Gregory
Fair enough, thanks for the info. I'll check out the source and see if I can put a patch together 'cos I'd really like this functionality.
Andrew Bullock
I added an answer to this question James, It'd be great if you could add a comment if my assumptions were correct or if I'm off base.
Chris Marisic
A: 

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.

Chris Marisic
Unfortunately I think OverrideAll can only (currently) be used to ignore properties on any entity, not for what Andrew is looking for.
James Gregory
A: 

I'm looking for this functionality too.

Simon Bartlett
A: 

Does this still apply (as per James's comment) or has something been done for this? I can't find any clear documentation if it has been fixed yet.

Bealer
You can probably do it with the conventions these days; a IHasManyToManyConvention and use the acceptance criteria interface to apply it to only comment types
Andrew Bullock
I'm trying to do this but my implementation of IHasManyToManyConvention.Apply doesn't even get hit; any idea what I'm missing here?
Sandor Drieënhuizen
have you told your FNH config where to look for your conventions?
Andrew Bullock

related questions