-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Model validation for primitive collections #31680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Microsoft.EntityFrameworkCore.Metadata.Conventions; | ||
|
|
||
| /// <summary> | ||
| /// A convention that ensures property mappings have any ElementMapping discovered by the type mapper. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// See <see href="https://aka.ms/efcore-docs-conventions">Model building conventions</see> for more information and examples. | ||
| /// </para> | ||
| /// </remarks> | ||
| public class ElementMappingConvention : IModelFinalizingConvention | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Merge this into type mapping convention
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AndriySvyryd What do you mean by "type mapping convention?"
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, looks like we've removed it already. This can also be calculated in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think this needs to get revisited after 8. Related #31417.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filed #31702. |
||
| { | ||
| /// <summary> | ||
| /// Creates a new instance of <see cref="ElementMappingConvention" />. | ||
| /// </summary> | ||
| /// <param name="dependencies">Parameter object containing dependencies for this convention.</param> | ||
| public ElementMappingConvention(ProviderConventionSetBuilderDependencies dependencies) | ||
| { | ||
| Dependencies = dependencies; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Dependencies for this service. | ||
| /// </summary> | ||
| protected virtual ProviderConventionSetBuilderDependencies Dependencies { get; } | ||
|
|
||
| /// <inheritdoc /> | ||
| public void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context) | ||
| { | ||
| foreach (var entityType in modelBuilder.Metadata.GetEntityTypes()) | ||
| { | ||
| Validate(entityType); | ||
| } | ||
|
|
||
| void Validate(IConventionTypeBase typeBase) | ||
| { | ||
| foreach (var property in typeBase.GetDeclaredProperties()) | ||
| { | ||
| var typeMapping = Dependencies.TypeMappingSource.FindMapping((IProperty)property); | ||
| if (typeMapping is { ElementTypeMapping: not null }) | ||
| { | ||
| property.SetElementType(property.ClrType.TryGetElementType(typeof(IEnumerable<>))); | ||
| } | ||
| } | ||
|
|
||
| foreach (var complexProperty in typeBase.GetDeclaredComplexProperties()) | ||
| { | ||
| Validate(complexProperty.ComplexType); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.