-
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.
Discover the compiled model automatically
Also add a way to manually reference the compiled model before it's generated Tests tracked by #33136 Fixes #24893
- Loading branch information
1 parent
a2b8f2c
commit 7bed44b
Showing
67 changed files
with
1,539 additions
and
179 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// 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.Infrastructure; | ||
|
||
/// <summary> | ||
/// Identifies the <see cref="RuntimeModel" /> implementation that should be used for a given context. | ||
/// </summary> | ||
/// <remarks> | ||
/// <para> | ||
/// This attribute will usually be generated with the compiled model and doesn't need to be specified in your code. | ||
/// </para> | ||
/// <para> | ||
/// See <see href="https://aka.ms/efcore-docs-dbcontext-pooling">Using DbContext pooling</see> for more information and examples. | ||
/// </para> | ||
/// </remarks> | ||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] | ||
public sealed class DbContextModelAttribute : Attribute | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DbContextAttribute" /> class. | ||
/// </summary> | ||
/// <param name="contextType">The associated context.</param> | ||
/// <param name="modelType">The compiled model.</param> | ||
public DbContextModelAttribute(Type contextType, Type modelType) | ||
{ | ||
Check.NotNull(contextType, nameof(contextType)); | ||
|
||
ContextType = contextType; | ||
ModelType = modelType; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the associated context. | ||
/// </summary> | ||
public Type ContextType { get; } | ||
|
||
/// <summary> | ||
/// Gets the compiled model. | ||
/// </summary> | ||
public Type ModelType { get; } | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
9 changes: 9 additions & 0 deletions
9
...s.FunctionalTests/Scaffolding/Baselines/Basic_cosmos_model/DbContextAssemblyAttributes.cs
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,9 @@ | ||
// <auto-generated /> | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using TestNamespace; | ||
|
||
#pragma warning disable 219, 612, 618 | ||
#nullable disable | ||
|
||
[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] |
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
9 changes: 9 additions & 0 deletions
9
...e.Cosmos.FunctionalTests/Scaffolding/Baselines/SimpleModel/DbContextAssemblyAttributes.cs
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,9 @@ | ||
// <auto-generated /> | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using TestNamespace; | ||
|
||
#pragma warning disable 219, 612, 618 | ||
#nullable disable | ||
|
||
[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] |
Oops, something went wrong.