ForeignKeyConstraintName for References
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?
Support Staff 2 Posted by James Gregory on 16 May, 2010 05:23 PM
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.
3 Posted by dario-g on 18 Nov, 2010 03:00 PM
Unfortunately EntityType is null even in 1.1 version. :(