Showing changes from revision #2 to #3: Added | Removed
So your existing conventions have broke with the introduction of the new convention style. I realise you're probably annoyed that your build is broken, but take a breath and make sure you've read Conventions and Conventions Interfaces. Once you've done that, if you still don't know what to do to fix your application, this might help.
Below are all the original conventions (or near enough) with their equivalent in the new-style. The logic change can be summarised as: old conventions were applied to everything, always; new style conventions are applied conditionally.
I'll show some examples of updating your conventions after the table.
Old Style | New Style |
---|---|
ITypeConvention |
Implement an IClassConvention |
IPropertyConvention |
Same but different method names |
Conventions.GetTableName |
Implement an IClassConvention or Convention Shortcuts
|
Conventions.GetPrimaryKeyName and Conventions.GetPrimaryKeyNameFromType |
Implement an IIdConvention or Convention Shortcuts
|
Conventions.GetForeignKeyName |
Implement an IHasManyConvention or other related relationship convention |
Conventions.GetReadOnlyCollectionBackingFieldName |
Implement an IHasManyConvention or other related relationship convention |
Conventions.IdConvention |
Implement an IIdConvention |
Conventions.OneToManyConvention |
Implement an IHasManyConvention |
Conventions.ManyToOneConvention |
Implement an IReferenceConvention |
Conventions.OneToOneConvention |
Implement an IHasOneConvention |
Conventions.GetManyToManyTableName |
Implement an IHasManyToManyConvention |
Conventions.JoinConvention |
Implement an IJoinConvention |
Conventions.DefaultCache |
Implement an IClassConvention or Convention Shortcuts
|
Conventions.GetVersionColumnName |
Implement an IVersionConvention |
Conventions.DefaultLazyLoad |
Implement an IClassConvention or Convention Shortcuts
|
Conventions.DynamicUpdate |
Implement an IClassConvention or Convention Shortcuts
|
Conventions.DynamicInsert |
Implement an IClassConvention or Convention Shortcuts
|
Conventions.GetComponentColumnPrefix |
Implement an IComponentConvention |
It goes without saying that implementing interfaces is going to be more verbose than using in-line lambdas, so prepare yourself because these conversions are going to end up being longer; however, the added separation makes for a much less coupled design. Learn to love it.
You should read up on the conventions in general and what interfaces are available.
Primary Key naming
You used to write the following to override the primary key naming to be TableNameId:
.WithConvention(c => c.GetPrimaryKeyName = type => type.Name + "Id");Now you'd implement an `IIdConvention` which allows you to alter the actual Id mapping itself.
public class PrimaryKeyNamingConvention : IIdConvention { public bool Accept(IIdentityPart id) { return true; // work on ALL ids } public void Apply(IIdentityPart id) { id.ColumnName(id.EntityType.Name + "Id"); } }That's your new convention, which you'd situate with all your other conventions, then use either of the following snippets to hook them in:
.ConventionDiscovery.AddFromAssemblyOf<PrimaryKeyNamingConvention>(); .ConventionDiscovery.Add<PrimaryKeyNamingConvention>();
Many-to-many table naming
You used to write the following to override the table name used for many-to-many relationships:
.WithConvention(c => c.GetManyToManyTableName = (child, parent) => child.Name + "To" + parent.Name);Now you'd implement an `IHasManyToManyConvention` which allows you to alter the actual many-to-many mapping itself.
public class ManyToManyTableNameConvention : IHasManyToManyConvention { public bool Accept(IManyToManyPart relationship) { return true; // work on ALL ids } public void Apply(IManyToManyPart relationship) { relationship.WithTableName(relationship.ChildType.Name + "To" + relationship.EntityType.Name); } }That's your new convention, which you'd situate with all your other conventions, then use either of the following snippets to hook them in:
.ConventionDiscovery.AddFromAssemblyOf< ManyToManyTableNameConvention>(); .ConventionDiscovery.Add< ManyToManyTableNameConvention>();
A note on auto-mapping:auto-mapping
If you're using automapping, the conventions used to be mixed up together. Now anything that can be thought of configuring the automapper's discovery capabilities (for example IsBaseType
) is now available only under the WithSetup
method (which in-part replaces WithConvention
), everything else is a standard convention and is handled through the ConventionDiscovery
property like the regular conventions.
// old .WithConvention(c => c.IsBaseType = type => type == typeof(BaseEntity)); // new .WithSetup(s => s.IsBaseType = type => type == typeof(BaseEntity))
If you were using the ForAttribute<T>
method, then you can inherit from the AttributePropertyConvention
abstract class.
public class MyAttributeConvention : AttributePropertyConvention<MyCustomAttribute> { public override void Apply(MyCustomAttribute attribute, IProperty property) { // your alterations } }