/// <summary> /// Sets the following conventions: /// 1) Foreign key fields are named as the property name suffixed by the value of _foreignKeyColumnSuffix. /// 2) Many to Many link tables are named as the object type names sorted alphabetically with the _manyToManyLinkTableInsert inserted inbetween them. /// </summary> private void BeforeMappingCollectionConvention( IModelInspector inspector, PropertyPath member, ICollectionPropertiesMapper customizer) { string tableName; if (inspector.IsManyToMany(member.LocalMember)) { tableName = this.GetManyToManyLinkTableName(member); customizer.Table(tableName); } else { tableName = member.GetCollectionElementType().Name; } string columnName = this.GetKeyColumnName(inspector, member); string foreignKeyName = $"{this._foreignKeyNamePrefix}{tableName}_{columnName}"; customizer.Key( k => { k.Column(columnName); k.ForeignKey(foreignKeyName); }); }
/// <summary> /// Gets the object type names for a many to many relationship sorted alphabetically. /// </summary> private static IEnumerable <string> GetManyToManySidesNames(PropertyPath member) { yield return(member.GetRootMemberType().Name); yield return(member.GetCollectionElementType().Name); }
/// <summary> /// Called when [to many other side property]. /// </summary> /// <param name="member">The member.</param> /// <returns></returns> public static MemberInfo OneToManyOtherSideProperty(this PropertyPath member) { return(member.GetCollectionElementType().GetFirstPropertyOfType(member.GetRootMemberType())); }