コード例 #1
0
        /// <summary>
        /// Starting from a relationship, function will figure out what the name of the object should be for a foriegn key, taking into account the potential names
        /// </summary>
        /// <param name="entity">Entity So we know the perspective of the relationship</param>
        /// <param name="FKName">String that is the name of the foriegn key we want to generated</param>
        /// <returns></returns>
        public static string GenerateObjectName(this IEntity entity, string FKName, ObjectNameGeneratedFrom generatedFrom)
        {
            var PROC_NAME = string.Format("EzDbSchemaRelationshipExtentions.GenerateObjectName(entity='{0}', FKName='{1}')", entity.Name, FKName);

            string FieldName = "";

            try
            {
                var relationship    = entity.RelationshipGroups[FKName];
                var relGroupSummary = relationship.AsSummary();
                var entityName      = entity.Schema + "." + entity.Name;

                int SameTableCount = 0;
                foreach (var rg in entity.RelationshipGroups.Values)
                {
                    if (rg.AsSummary().ToTableName.Equals(relGroupSummary.ToTableName))
                    {
                        SameTableCount++;
                    }
                }
                string ToTableNameSingular = relGroupSummary.ToTableName.Replace(Internal.AppSettings.Instance.Configuration.Database.DefaultSchema + ".", "").ToSingular();

                var AltName = ToTableNameSingular;
                if (relGroupSummary.FromTableName.Equals(relGroupSummary.ToTableName))
                {
                    generatedFrom = ObjectNameGeneratedFrom.ToUniqueColumnName;
                }
                switch (generatedFrom)
                {
                case ObjectNameGeneratedFrom.JoinFromColumnName:
                    AltName = string.Join(",", relGroupSummary.FromColumnName);
                    break;

                case ObjectNameGeneratedFrom.ToUniqueColumnName:
                    AltName = relGroupSummary.ToUniqueColumnName(false);
                    break;

                case ObjectNameGeneratedFrom.JoinToColumnName:
                    AltName = string.Join(",", relGroupSummary.ToColumnName);
                    break;
                }

                FieldName = (((entity.Properties.ContainsKey(ToTableNameSingular)) ||
                              (entityName == relGroupSummary.ToTableName) ||
                              (SameTableCount > 1))
                                        ? AltName : ToTableNameSingular);
            } catch (Exception ex)
            {
                throw new Exception(PROC_NAME + ".  " + ex.Message);
            }
            return(FieldName);
        }
コード例 #2
0
        /// <summary>
        /// Starting from a relationship, function will figure out what the name of the object should be for a foriegn key, taking into account the potential names
        /// </summary>
        /// <param name="This">The FK to generate the object from</param>
        /// <param name="entity">Entity So we know the perspective of the relationship</param>
        /// <returns></returns>
        public static string GenerateObjectName(this IRelationship This, IEntity entity, ObjectNameGeneratedFrom generatedFrom)
        {
            var FKName = This.Name;

            return(entity.GenerateObjectName(FKName, generatedFrom));
        }