-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pre-convention model configuration infrastructure
Fixes #12229
- Loading branch information
1 parent
6449203
commit dd315f6
Showing
51 changed files
with
1,373 additions
and
827 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.EntityFrameworkCore.Metadata.Internal | ||
{ | ||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// 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 partial class ModelConfiguration | ||
{ | ||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// 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 ModelConfiguration() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// 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 bool IsEmpty() | ||
=> true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.ComponentModel; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Metadata.Conventions; | ||
using Microsoft.EntityFrameworkCore.Metadata.Internal; | ||
using Microsoft.EntityFrameworkCore.Utilities; | ||
|
||
namespace Microsoft.EntityFrameworkCore | ||
{ | ||
/// <summary> | ||
/// <para> | ||
/// Provides a simple API surface for setting defaults and configuring conventions before they run. | ||
/// </para> | ||
/// <para> | ||
/// You can use <see cref="ModelConfigurationBuilder" /> to configure the conventions for a context by overriding | ||
/// <see cref="DbContext.ConfigureConventions(ModelConfigurationBuilder)" /> on your derived context. | ||
/// Alternatively you can create the model externally and set it on a <see cref="DbContextOptions" /> instance | ||
/// that is passed to the context constructor. | ||
/// </para> | ||
/// </summary> | ||
public class ModelConfigurationBuilder | ||
{ | ||
private readonly ModelConfiguration _modelConfiguration = new(); | ||
private readonly ConventionSet _conventions; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ModelConfigurationBuilder" />. | ||
/// </summary> | ||
/// <param name="conventions"> The conventions to be applied during model building. </param> | ||
public ModelConfigurationBuilder(ConventionSet conventions) | ||
{ | ||
Check.NotNull(conventions, nameof(conventions)); | ||
|
||
_conventions = conventions; | ||
} | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// 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> | ||
[EntityFrameworkInternal] | ||
protected virtual ModelConfiguration ModelConfiguration => _modelConfiguration; | ||
|
||
/// <summary> | ||
/// Creates the configured <see cref="ModelBuilder" /> used to create the model. This is done automatically when using | ||
/// <see cref="DbContext.OnModelCreating" />; this method allows it to be run | ||
/// explicitly in cases where the automatic execution is not possible. | ||
/// </summary> | ||
/// <param name="modelDependencies"> The dependencies object used during model building. </param> | ||
/// <returns> The configured <see cref="ModelBuilder" />. </returns> | ||
public virtual ModelBuilder CreateModelBuilder(ModelDependencies? modelDependencies) | ||
=> new(_conventions, modelDependencies, _modelConfiguration.IsEmpty() ? null : _modelConfiguration); | ||
|
||
#region Hidden System.Object members | ||
|
||
/// <summary> | ||
/// Returns a string that represents the current object. | ||
/// </summary> | ||
/// <returns> A string that represents the current object. </returns> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public override string? ToString() | ||
=> base.ToString(); | ||
|
||
/// <summary> | ||
/// Determines whether the specified object is equal to the current object. | ||
/// </summary> | ||
/// <param name="obj"> The object to compare with the current object. </param> | ||
/// <returns> <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" />. </returns> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public override bool Equals(object? obj) | ||
=> base.Equals(obj); | ||
|
||
/// <summary> | ||
/// Serves as the default hash function. | ||
/// </summary> | ||
/// <returns> A hash code for the current object. </returns> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public override int GetHashCode() | ||
=> base.GetHashCode(); | ||
|
||
#endregion | ||
} | ||
} |
Oops, something went wrong.