Weird case with a legacy database: Most tables have the same named field for the primary key, but I have one table that has a different primary key but also has that named field. When I override the automap for this table it uses the convention not the override unless I explicitly override the mapping for the name field.
public class IdConvention : IIdConvention, IIdConventionAcceptance,
{
public void Accept(IAcceptanceCriteria<IIdentityInspector> criteria)
{
criteria.Expect(x => x.Type == typeof(string));
}
public void Apply(IIdentityInstance instance)
{
if (instance.Name == "StandardId")
instance.Column("FooBarThingyId");
}
}
public class WierdCase
{
virtual int CustomId {get;set;}
virtual int StandardId {get;set;}
}
public class WierdCaseOverride : IAutoMappingOverride<WierdCase>
{
public void Override(AutoMapping<WierdCase> mapping)
{
mapping.Id(x => x.CustomId).GeneratedBy.Identity();
mapping.Map(x => x.StandardId , "FooBarThingyId");
}
}
public class CustomConfiguration : DefaultAutomappingConfiguration
{
public override bool IsId(Member member)
{
if (member.DeclaringType.GetProperty("StandardId") != null)
return member.Name == "StandardId";
return base.IsId(member);
}
}
Without the mapping.Map() line, this uses StandardId as the key, not CustomId. I would expect calling mapping.Id() to override the convention, but it does not seem to.
What am I missing here? As I'd rather fix the convention than have to explicitly override it for the exceptions.