ForeignKeyConstraintName for References

Tristian Barrett's Avatar

Tristian Barrett

06 May, 2010 11:18 AM via web

Hi Guys,

We're running the 1.0 RTM and mainly using AutoMapper.

My aim is to have the foreign key names look like so:
(For ManyToOne) (For OneToMany)

I've setup a convention for Foreign Key Constraints so like so:

public class ForeignKeyConstraintName : IHasManyConvention, IReferenceConvention

{
    public void Apply(IOneToManyCollectionInstance instance)
    {
        var keyName = String.Format("FK_{0}_{1}", instance.Member.Name, Inflector.Pluralize(instance.EntityType.Name));
        instance.Key.ForeignKey(keyName);
    }

    public void Apply(IManyToOneInstance instance)
    {
        var keyName = String.Format("FK_{0}_{1}", Inflector.Pluralize(instance.EntityType.Name), instance.Property.PropertyType.Name);
        instance.ForeignKey(keyName);
    }
}

The thing is: the OneToMany apply works fine, but the ManyToOne fails because it can't find the EntityType. There doesn't seem to be any properties on the IManyToOneInstance that can be used to get the table name the property is on.

Am I going about this the right way, and if sowhy is the EntityType comming up blank?

  1. Support Staff 2 Posted by James Gregory on 16 May, 2010 05:23 PM

    James Gregory's Avatar

    I would suggest you try updating to the latest version, we've had a lot of fixes go in since RTM. We've got an 1.1 release landing imminently.

  2. 3 Posted by dario-g on 18 Nov, 2010 03:00 PM

    dario-g's Avatar

    Unfortunately EntityType is null even in 1.1 version. :(

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    What is the last month of the year?