/// <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); }
/// <summary> /// Returns the database schema that contains the mapped table. /// </summary> /// <param name="entityType">The entity type to get the schema for.</param> /// <returns>The database schema that contains the mapped table.</returns> public static string?GetSchema(this IReadOnlyEntityType entityType) { if (entityType.GetTableName() == null) { return(null); } var schemaAnnotation = entityType.FindAnnotation(RelationalAnnotationNames.Schema); if (schemaAnnotation != null) { return((string?)schemaAnnotation.Value ?? GetDefaultSchema(entityType)); } return(entityType.BaseType != null ? entityType.GetRootType().GetSchema() : GetDefaultSchema(entityType)); }