コード例 #1
0
        private static string DetermineKeyColumnName(IModelInspector inspector, PropertyPath member)
        {
            var otherSideProperty = member.OneToManyOtherSideProperty();
            if (inspector.IsOneToMany(member.LocalMember) && otherSideProperty != null)
                return otherSideProperty.Name + ForeignKeyColumnPostfix;

            return member.Owner().Name + ForeignKeyColumnPostfix;
        }
        protected virtual void OnBeforeMappingCollectionConvention(IModelInspector modelinspector, PropertyPath member, ICollectionPropertiesMapper collectionPropertiesCustomizer)
        {
            if (modelinspector.IsManyToMany(member.LocalMember))
            {
                collectionPropertiesCustomizer.Table(member.ManyToManyIntermediateTableName("To"));
            }

            if (modelinspector.IsSet(member.LocalMember))
            {
                // If otherside has many-to-one, make it inverse, if not specify foreign key on Key element
                MemberInfo oneToManyProperty = member.OneToManyOtherSideProperty();
                IEnumerable<MemberInfo> candidatesManyToOne =
                    MembersProvider
                        .GetRootEntityMembers(oneToManyProperty.DeclaringType)
                        .Where(modelinspector.IsManyToOne);
                if (candidatesManyToOne.Any(mi => mi.MemberType() == member.LocalMember.DeclaringType))
                {
                    collectionPropertiesCustomizer.Inverse(true);
                }
                else
                {
                    Contract.Assert(oneToManyProperty.DeclaringType != null, "otherSideProperty.DeclaringType != null");
                    collectionPropertiesCustomizer.Key(k => k.ForeignKey(string.Format("FK_{0}_{1}", oneToManyProperty.DeclaringType.Name, oneToManyProperty.Name)));
                }
            }

            collectionPropertiesCustomizer.Key(k => k.Column(GetKeyColumnName(modelinspector, member)));
        }
 protected virtual string GetKeyColumnName(IModelInspector modelInspector, PropertyPath member)
 {
     MemberInfo otherSideProperty = member.OneToManyOtherSideProperty();
     Type type = modelInspector.IsOneToMany(member.LocalMember) && otherSideProperty != null
                     ? otherSideProperty.MemberType()
                     : member.MemberType();
     return GetKeyColumnName(modelInspector, type, true);
 }
コード例 #4
0
        /// <summary>
        /// Gets the foreign key field name to use for a property.
        /// </summary>
        private string GetKeyColumnName(IModelInspector inspector, PropertyPath member)
        {
            var otherSideProperty = member.OneToManyOtherSideProperty();
            if (inspector.IsOneToMany(member.LocalMember) && otherSideProperty != null)
            {
                return otherSideProperty.Name + _foreignKeyColumnSuffix;

            }

            return member.GetRootMemberType().Name + _foreignKeyColumnSuffix;
        }