示例#1
0
        /// <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 = GetManyToManyLinkTableName(member);
                customizer.Table(tableName);
            }
            else
            {
                tableName = member.GetCollectionElementType().Name;
            }

            string columnName = GetKeyColumnName(inspector, member);
            string foreignKeyName = string.Format("{0}{1}_{2}", _foreignKeyNamePrefix, tableName, columnName);
            customizer.Key(k =>
            {
                k.Column(columnName);
                k.ForeignKey(foreignKeyName);
            });
        }
示例#2
0
 /// <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;
 }