-
Notifications
You must be signed in to change notification settings - Fork 684
Converting to new style conventions
I'd advise that you read about the conventions first, and the available conventions, once you understand how the new conventions work you can use this page to help migrate any existing ones.
- Replacing existing conventions
I'll show some examples of updating your conventions after the table.
Old style | New style |
---|---|
ITypeConvention | IClassConvention |
IPropertyConvention | Same but different signature |
Conventions.GetTableName | IClassConvention or a convention shortcut |
Conventions.GetPrimaryKeyName and Conventions.GetPrimaryKeyNameFromType | IIdConvention or a convention shortcut |
Conventions.GetForeignKeyName | ForeignKeyConvention base-class, or the specific relationship interface you need (IHasManyConvention for example). |
Conventions.GetReadOnlyCollectionBackingFieldName | ICollectionConvention |
Conventions.IdConvention | IIdConvention |
Conventions.OneToManyConvention | IHasManyConvention |
Conventions.ManyToOneConvention | IReferenceConvention |
Conventions.OneToOneConvention | IHasOneConvention |
Conventions.GetManyToManyTableName | ManyToManyTableNameConvention base-class |
Conventions.JoinConvention | IJoinConvention |
Conventions.DefaultCache | IClassConvention or a convention shortcut |
Conventions.GetVersionColumnName | IVersionConvention |
Conventions.DefaultLazyLoad | IClassConvention or a convention shortcut |
Conventions.DynamicUpdate | IClassConvention or a convention shortcut |
Conventions.DynamicInsert | IClassConvention or a convention shortcut |
Conventions.GetComponentColumnPrefix | IComponentConvention |
- Primary Key naming
.WithConvention(c => c.GetPrimaryKeyName = type => type.Name + "Id");
Now you'd implement an IIdConvention which allows you to alter the actual Id mapping itself.
} }
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:
.Conventions.AddFromAssemblyOf<PrimaryKeyNamingConvention>(); .Conventions.Add<PrimaryKeyNamingConvention>();
- Many-to-many table naming
.WithConvention(c => c.GetManyToManyTableName = (child, parent) => child.Name + "To" + parent.Name);
Now you'd derive from the ManyToManyTableNameConvention which already has all the logic created for setting the other side of bi-directional relationships, and knows not to overwrite the table names if one already is set.
protected override string GetUniDirectionalTableName(IManyToManyCollectionInspector collection) { return collection.EntityType.Name + "To" + collection.ChildType.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:
.Conventions.AddFromAssemblyOf<ManyToManyTableNameConvention>(); .Conventions.Add<ManyToManyTableNameConvention>();
- Automapping
IsBaseType
) is now available only under the Setup
method (which in-part replaces WithConvention
), everything else is a standard convention and is handled through the Conventions
property like conventions.
// old .WithConvention(c => c.IsBaseType = type => type == typeof(BaseEntity));
// new .Setup(s => s.IsBaseType = type => type == typeof(BaseEntity))
- Attribute based conventions
ForAttribute<T>
method, then you can inherit from the `AttributePropertyConvention` base-class.