Пример #1
0
        /// <summary>
        /// Gets the string represetnation of the object.
        /// </summary>
        /// <returns></returns>
        public string ToString(SqlDialect dialect)
        {
            // return...
            if (dialect != null)
            {
                return(dialect.FormatNativeName(this));
            }

            // create...
            if (this.CatalogName == null && this.UserName == null)
            {
                return(this.Name);
            }

            // do we have a catalogname?
            if (this.CatalogName != null)
            {
                if (this.UserName != null)
                {
                    return(string.Format("{0}.{1}.{2}", this.CatalogName, this.UserName, this.Name));
                }
                else
                {
                    return(string.Format("{0}..{1}", this.CatalogName, this.Name));
                }
            }

            // username?
            return(string.Format("{0}.{1}", this.UserName, this.Name));
        }
Пример #2
0
        /// <summary>
        /// Returns true if the property is being used.
        /// </summary>
        /// <param name="entityType"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public override bool IsPropertyInUse(EntityType entityType, string name)
        {
            if (entityType == null)
            {
                throw new ArgumentNullException("entityType");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length == 0)
            {
                throw new ArgumentOutOfRangeException("'name' is zero-length.");
            }

            // table?
            if (IsExtendedPropertiesTableCreated(entityType))
            {
                // dialect...
                SqlDialect dialect = entityType.Dialect;
                if (dialect == null)
                {
                    throw new InvalidOperationException("dialect is null.");
                }

                // find it...
                StringBuilder builder = new StringBuilder();
                builder.Append(dialect.SelectKeyword);
                builder.Append(" TOP 1 ");
                builder.Append(dialect.FormatColumnName("Name"));
                builder.Append(" ");
                builder.Append(dialect.FromKeyword);
                builder.Append(" ");
                builder.Append(dialect.FormatNativeName(entityType.NativeNameExtended));
                builder.Append(" ");
                builder.Append(dialect.WhereKeyword);
                builder.Append(" ");
                builder.Append(dialect.FormatColumnName("Name"));
                builder.Append("=");
                const string paramName = "name";
                builder.Append(dialect.FormatVariableNameForQueryText(paramName));

                // create...
                SqlStatement statement = new SqlStatement(builder.ToString());
                statement.Parameters.Add(new SqlStatementParameter(paramName, DbType.String, name));

                // run...
                object result = Database.ExecuteScalar(statement);
                if (result is string)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }