-
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.
Fix for 4050. IndexAttribute. (#21012)
Fix for 4050. Add a new IndexAttribute.
- Loading branch information
Showing
60 changed files
with
2,392 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// 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; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore.Utilities; | ||
|
||
namespace Microsoft.EntityFrameworkCore | ||
{ | ||
/// <summary> | ||
/// Specifies an index to be generated in the database. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] | ||
public sealed class IndexAttribute : Attribute | ||
{ | ||
private static readonly bool DefaultIsUnique = false; | ||
private bool? _isUnique; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="IndexAttribute" /> class. | ||
/// </summary> | ||
/// <param name="propertyNames"> The properties which constitute the index, in order (there must be at least one). </param> | ||
public IndexAttribute(params string[] propertyNames) | ||
{ | ||
Check.NotEmpty(propertyNames, nameof(propertyNames)); | ||
Check.HasNoEmptyElements(propertyNames, nameof(propertyNames)); | ||
PropertyNames = propertyNames.ToList(); | ||
} | ||
|
||
/// <summary> | ||
/// The properties which constitute the index, in order. | ||
/// </summary> | ||
public List<string> PropertyNames { get; } | ||
|
||
/// <summary> | ||
/// The name of the index. | ||
/// </summary> | ||
public string Name { get; [param: NotNull] set; } | ||
|
||
|
||
/// <summary> | ||
/// Whether the index is unique. | ||
/// </summary> | ||
public bool IsUnique | ||
{ | ||
get => _isUnique ?? DefaultIsUnique; | ||
set => _isUnique = value; | ||
} | ||
|
||
/// <summary> | ||
/// Use this method if you want to know the uniqueness of | ||
/// the index or <see langword="null"/> if it was not specified. | ||
/// </summary> | ||
public bool? GetIsUnique() => _isUnique; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/EFCore.Abstractions/Properties/AbstractionsStrings.Designer.cs
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
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
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,54 @@ | ||
// 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; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Diagnostics | ||
{ | ||
/// <summary> | ||
/// A <see cref="DiagnosticSource" /> event payload class for | ||
/// the events involving an invalid index. | ||
/// </summary> | ||
public class IndexEventData : EventData | ||
{ | ||
/// <summary> | ||
/// Constructs the event payload for events involving an invalid index. | ||
/// </summary> | ||
/// <param name="eventDefinition"> The event definition. </param> | ||
/// <param name="messageGenerator"> A delegate that generates a log message for this event. </param> | ||
/// <param name="entityType"> The entity type on which the index is defined. </param> | ||
/// <param name="indexName"> The name of the index. </param> | ||
/// <param name="indexPropertyNames"> The names of the properties which define the index. </param> | ||
public IndexEventData( | ||
[NotNull] EventDefinitionBase eventDefinition, | ||
[NotNull] Func<EventDefinitionBase, EventData, string> messageGenerator, | ||
[NotNull] IEntityType entityType, | ||
[CanBeNull] string indexName, | ||
[NotNull] List<string> indexPropertyNames) | ||
: base(eventDefinition, messageGenerator) | ||
{ | ||
EntityType = entityType; | ||
Name = indexName; | ||
PropertyNames = indexPropertyNames; | ||
} | ||
|
||
/// <summary> | ||
/// The entity type on which the index is defined. | ||
/// </summary> | ||
public virtual IEntityType EntityType { get; } | ||
|
||
/// <summary> | ||
/// The name of the index. | ||
/// </summary> | ||
public virtual string Name { get; } | ||
|
||
/// <summary> | ||
/// The list of properties which define the index. | ||
/// </summary> | ||
public virtual List<string> PropertyNames { get; } | ||
} | ||
} |
Oops, something went wrong.