Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,9 @@ private void GenerateAddMapping(
}

var table = tableMapping.Table;
var isOptional = table.IsOptional(typeBase);
var isOptional = typeBase.IsMappedToJson()
? (bool?)null
: table.IsOptional(typeBase);
mainBuilder
.AppendLine($"{tableVariable}.AddTypeMapping({tableMappingVariable}, {code.Literal(isOptional)});")
.AppendLine($"{tableMappingsVariable}.Add({tableMappingVariable});");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,18 @@ static void ValidateType(ITypeBase typeBase)
}

/// <inheritdoc/>
protected override void ValidatePropertyMapping(IConventionComplexProperty complexProperty)
protected override void ValidatePropertyMapping(
IConventionComplexProperty complexProperty,
IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
{
base.ValidatePropertyMapping(complexProperty);
base.ValidatePropertyMapping(complexProperty, logger);

if (complexProperty.IsCollection && !complexProperty.ComplexType.IsMappedToJson())
{
throw new InvalidOperationException(
RelationalStrings.ComplexCollectionNotMappedToJson(
complexProperty.DeclaringType.DisplayName(), complexProperty.Name));
}

if (!complexProperty.ComplexType.IsMappedToJson()
&& complexProperty.IsNullable
Expand Down
10 changes: 6 additions & 4 deletions src/EFCore.Relational/Metadata/Internal/TableBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,13 @@ public override bool IsReadOnly
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual void AddTypeMapping(ITableMappingBase tableMapping, bool optional)
public virtual void AddTypeMapping(ITableMappingBase tableMapping, bool? optional)
{
OptionalTypes ??= new Dictionary<ITypeBase, bool>();

OptionalTypes.Add(tableMapping.TypeBase, optional);
if (optional.HasValue)
{
OptionalTypes ??= [];
OptionalTypes.Add(tableMapping.TypeBase, optional.Value);
}

if (tableMapping.TypeBase is IEntityType)
{
Expand Down
52 changes: 30 additions & 22 deletions src/EFCore.Relational/Properties/RelationalStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 13 additions & 10 deletions src/EFCore.Relational/Properties/RelationalStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@
<data name="CompiledModelFunctionTranslation" xml:space="preserve">
<value>The function '{function}' has a custom translation. Compiled model can't be generated, because custom function translations are not supported.</value>
</data>
<data name="ComplexCollectionNotMappedToJson" xml:space="preserve">
<value>The complex collection property '{entityType}.{property}' must be mapped to a JSON column. Use 'ToJson()' to configure this complex collection as mapped to a JSON column.</value>
</data>
<data name="ComplexPropertyBothJsonColumnAndJsonPropertyName" xml:space="preserve">
<value>Complex property '{complexProperty}' cannot have both a JSON column name ('{columnName}') and a JSON property name ('{propertyName}') configured. Use ToJson() to map to a JSON column or HasJsonPropertyName() to map as a JSON property within a containing JSON column, but not both.</value>
</data>
Expand All @@ -157,9 +160,6 @@
<data name="ComplexPropertyJsonPropertyNameWithoutJsonMapping" xml:space="preserve">
<value>Complex property '{complexProperty}' cannot use 'HasJsonPropertyName()' because it is not contained within a JSON-mapped type. Use 'ToJson()' to map the complex property to a JSON column, or ensure it is contained within a type that is mapped to JSON.</value>
</data>
<data name="PropertyBothColumnNameAndJsonPropertyName" xml:space="preserve">
<value>Property '{property}' cannot have both a column name ('{columnName}') and a JSON property name ('{jsonPropertyName}') configured. Properties in JSON-mapped types should use JSON property names, not column names.</value>
</data>
<data name="ComplexPropertyOptionalTableSharing" xml:space="preserve">
<value>The optional complex property '{type}.{property}' is mapped to columns by flattening the contained properties, but it only contains optional properties. Add a required property or discriminator or map this complex property to a JSON column.</value>
</data>
Expand Down Expand Up @@ -439,12 +439,12 @@
<data name="ExecuteUpdateDeleteOnEntityNotMappedToTable" xml:space="preserve">
<value>ExecuteUpdate or ExecuteDelete was called on entity type '{entityType}', but that entity type is not mapped to a table.</value>
</data>
<data name="ExecuteUpdateSubqueryNotSupportedOverComplexTypes" xml:space="preserve">
<value>ExecuteUpdate is being used over a LINQ operator which isn't natively supported by the database; this cannot be translated because complex type '{complexType}' is projected out. Rewrite your query to project out the containing entity type instead.</value>
</data>
<data name="ExecuteUpdateOverJsonIsNotSupported" xml:space="preserve">
<value>ExecuteUpdate is being used over type '{structuralType}' which is mapped to JSON; ExecuteUpdate on JSON is not supported.</value>
</data>
<data name="ExecuteUpdateSubqueryNotSupportedOverComplexTypes" xml:space="preserve">
<value>ExecuteUpdate is being used over a LINQ operator which isn't natively supported by the database; this cannot be translated because complex type '{complexType}' is projected out. Rewrite your query to project out the containing entity type instead.</value>
</data>
<data name="ExplicitDefaultConstraintNamesNotSupportedForTpc" xml:space="preserve">
<value>Can't use explicitly named default constraints with TPC inheritance or entity splitting. Constraint name: '{explicitDefaultConstraintName}'.</value>
</data>
Expand Down Expand Up @@ -806,7 +806,7 @@
<comment>Warning RelationalEventId.ModelValidationKeyDefaultValueWarning string string</comment>
</data>
<data name="LogKeyPropertiesNotMappedToTable" xml:space="preserve">
<value>The key {keyProperties} on the entity type '{entityType}' cannot be represented in the database. Either all or some of the properties aren't mapped to table '{table}'. All key properties must be mapped to a single table for the unique constraint to be created.</value>
<value>The key {keyProperties} on the entity type '{entityType}' cannot be represented in the database. Some or all of the properties aren't mapped to table '{table}'. All key properties must be mapped to a single table for the unique constraint to be created.</value>
<comment>Error RelationalEventId.KeyPropertiesNotMappedToTable string string string</comment>
</data>
<data name="LogMigrating" xml:space="preserve">
Expand Down Expand Up @@ -962,7 +962,7 @@
<value>Using '{methodName}' on DbSet of '{entityType}' is not supported since '{entityType}' is part of hierarchy and does not contain a discriminator property.</value>
</data>
<data name="MigrationDownMissing" xml:space="preserve">
<value>The 'Down' method for this migration has not been implemented. Both the 'Up' abd 'Down' methods must be implemented to support reverting migrations.</value>
<value>The 'Down' method for this migration has not been implemented. Both the 'Up' and 'Down' methods must be implemented to support reverting migrations.</value>
</data>
<data name="MigrationNotFound" xml:space="preserve">
<value>The migration '{migrationName}' was not found.</value>
Expand All @@ -980,7 +980,7 @@
<value>No value was provided for the required parameter '{parameter}'.</value>
</data>
<data name="MissingResultSetWhenSaving" xml:space="preserve">
<value>A result set was was missing when reading the results of a SaveChanges operation; this may indicate that a stored procedure was configured to return results in the EF model, but did not. Check your stored procedure definitions.</value>
<value>A result set was missing when reading the results of a SaveChanges operation; this may indicate that a stored procedure was configured to return results in the EF model, but did not. Check your stored procedure definitions.</value>
</data>
<data name="ModificationCommandBatchAlreadyComplete" xml:space="preserve">
<value>Cannot add commands to a completed ModificationCommandBatch.</value>
Expand Down Expand Up @@ -1078,6 +1078,9 @@
<data name="ProjectionMappingCountMismatch" xml:space="preserve">
<value>Unable to translate set operations when both sides don't assign values to the same properties in the nominal type. Please make sure that the same properties are included on both sides, and consider assigning default values if a property doesn't require a specific value.</value>
</data>
<data name="PropertyBothColumnNameAndJsonPropertyName" xml:space="preserve">
<value>Property '{property}' cannot have both a column name ('{columnName}') and a JSON property name ('{jsonPropertyName}') configured. Properties in JSON-mapped types should use JSON property names, not column names.</value>
</data>
<data name="PropertyNotMapped" xml:space="preserve">
<value>The '{propertyType}' property '{entityType}.{property}' could not be mapped to the database type '{storeType}' because the database provider does not support mapping '{propertyType}' properties to '{storeType}' columns. Consider mapping to a different database type or converting the property value to a type supported by the database using a value converter. See https://aka.ms/efcore-docs-value-converters for more information. Alternately, exclude the property from the model using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.</value>
</data>
Expand Down Expand Up @@ -1223,7 +1226,7 @@
<value>The query requires a subquery over complex type '{complexType}'. Subqueries over complex types are currently unsupported.</value>
</data>
<data name="TableNotMappedEntityType" xml:space="preserve">
<value>The entity type '{entityType}' is not mapped to the store object '{table}'.</value>
<value>The type '{entityType}' is not mapped to the store object '{table}'.</value>
</data>
<data name="TableOverrideMismatch" xml:space="preserve">
<value>The property '{propertySpecification}' has specific configuration for the table '{table}', but isn't mapped to a column on that table. Remove the specific configuration, or map an entity type that contains this property to '{table}'.</value>
Expand Down
Loading
Loading