Billy,
I agree with James.
The beauty of the new conventions system is that you can selectively apply conventions to classes.
I notice from your comment about class exclusions and your comments in the PrimaryKeyConvention class in S#arp that you seem to be shying away from this.
I have been battling with how to apply conventions/overrides within my project and am now leaning towards James’ approach of targeted conventions with prescriptive class names .
So in S#arp’s Northwind sample we should have:
IdentityIdConvention
AssignedStringIdConvention
Rather than just PrimaryKeyConvention
We should have Pluralized and Singular table name conventions.
There should also Lazy and NonLazy class conventions which would again reduce the need for overrides and are more maintainable.
Just my 2 pennies
Martin
James/Billy,
Attached is a patch with my take on the conventions in Northwind example in S#arp Architecture (patched to revision 420).
James,
I would be particularly interested on your views and how you would approach it.
There are a couple of overrides still remaining.
The EmployeeTerritories many to many is a stumbling block. I feel that this should be a convention but not really sure how to achieve it.
See my comment in the ManyToManyTableNameConvention class for details:
public class ManyToManyTableNameConvention : IHasManyToManyConvention
{
public bool Accept(IManyToManyPart target)
{
return true;
}
public void Apply(IManyToManyPart target)
{
// want to be able to do something like the following to
// account for the EmployeeTerritories case:
// var tableName = target.IsInverse
// ?
// target.ChildType.Name + Inflector.Net.Inflector.Pluralize(target.EntityType.Name)
// :
// target.EntityType.Name + Inflector.Net.Inflector.Pluralize(target.ChildType.Name);
// target.WithTableName(tableName);
}
}
Cheers,
James,
One other thing that deserves mentioning is the IdentityIdConvention.
It accepts anything that isn’t accepted by the AssignedIdentityConvention like so:
public class IdentityIdConvention : IIdConvention
{
public bool Accept(IIdentityPart target)
{
return target.IdentityType == typeof (int) &!
(new AssignedIdConvention()).Accept(target);
}
public void Apply(IIdentityPart target)
{
target.GeneratedBy.Identity();
}
}
Assuming you don’t think this use case is garbage it would be useful to have a static method available for conventions to check whether a target would be accepted.
The above code could then be modified as follows:
public class IdentityIdConvention : IIdConvention
{
public bool Accept(IIdentityPart target)
{
return target.IdentityType == typeof (int) &!
AssignedIdConvention.Accepts(target);
}
public void Apply(IIdentityPart target)
{
target.GeneratedBy.Identity();
}
}
Thoughts?