Setting FK Constraint Name in Many-to-Many Convention
I'm trying to setup a convention for readable FK constraint names for my automapped models. I've been able to get it working for 1:M, M:1, and JoinedSubClass but I'm having trouble with M:M.
I can do it in my classmap or automappingoverride using something like:
mapping.HasManyToMany(x => x.Collection)
.ForeignKeyConstraintNames("FK_Parent", "FK_Child");
Basically, how can I set the equivalent values in a IHasManyToManyConvention?
I implement the IHasManyToManyConvention and I can set the Parent FK Constraint Name using:
public void Apply(IManyToManyCollectionInstance instance)
{
instance.Key.ForeignKey("parentKeyName");
}
but I can't figure out how to set the Child FK Constraint Name.
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by James Gregory on 24 Feb, 2010 09:43 AM
You should be able to do this:
Unfortunately, it seems we've missed that method off the conventions. I've created a ticket (#129) for this, and we'll get to it asap. We're currently two men down though, so we may not be able to get around to it until next week.
If you fancy taking this on yourself, I can point you to the right files.
3 Posted by David Archer on 24 Feb, 2010 02:50 PM
James,
Point away. :) I'll see what I can do.
-- David
Support Staff 4 Posted by James Gregory on 24 Feb, 2010 03:02 PM
Great, you're my favourite kind of user. :)
Firstly, if you take a look at Conventions/Instances/KeyInstance.cs you'll see that there's a
ForeignKey
method defined (exposed through the IKeyInstance interface). This is what you'll need to duplicate.The class that will need modifying is the Conventions/Instances/ManyToManyInstance.cs, and you should be able to use the exact same code from
KeyInstance
to create theForeignKey
method; you'll also need to expose the method through theIManyToManyInstance
interface.That should be all that you'll need to do. Let me know if that doesn't work.
5 Posted by David Archer on 24 Feb, 2010 06:32 PM
Just sent you a pull request on github for these changes plus unit tests.
Support Staff 6 Posted by Paul Batum on 28 Feb, 2010 01:27 PM
Pulled into my repository, it'll go into the trunk with the next batch. Thanks David.
Support Staff 7 Posted by James Gregory on 01 May, 2010 12:56 PM
Merged into master.
James Gregory resolved this discussion on 01 May, 2010 12:56 PM.