Ejemplo n.º 1
0
        /// <summary>
        ///     Creates an id for the store object that the given entity type is mapped to.
        /// </summary>
        /// <param name="entityType"> The entity type. </param>
        /// <param name="type"> The store object type. </param>
        /// <returns> The store object id. </returns>
        public static StoreObjectIdentifier?Create(IReadOnlyEntityType entityType, StoreObjectType type)
        {
            Check.NotNull(entityType, nameof(entityType));

            switch (type)
            {
            case StoreObjectType.Table:
                var tableName = entityType.GetTableName();
                return(tableName == null ? null : Table(tableName, entityType.GetSchema()));

            case StoreObjectType.View:
                var viewName = entityType.GetViewName();
                return(viewName == null ? null : View(viewName, entityType.GetViewSchema()));

            case StoreObjectType.SqlQuery:
                var query = entityType.GetSqlQuery();
                return(query == null ? null : SqlQuery(entityType));

            case StoreObjectType.Function:
                var functionName = entityType.GetFunctionName();
                return(functionName == null ? null : DbFunction(functionName));

            default:
                return(null);
            }
        }
    /// <summary>
    ///     Returns the name of the table to which the entity type is mapped prepended by the schema
    ///     or <see langword="null" /> if not mapped to a table.
    /// </summary>
    /// <param name="entityType">The entity type to get the table name for.</param>
    /// <returns>The name of the table to which the entity type is mapped prepended by the schema.</returns>
    public static string?GetSchemaQualifiedTableName(this IReadOnlyEntityType entityType)
    {
        var tableName = entityType.GetTableName();

        if (tableName == null)
        {
            return(null);
        }

        var schema = entityType.GetSchema();

        return((string.IsNullOrEmpty(schema) ? "" : schema + ".") + tableName);
    }