36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
using System;
|
|
using AMWD.Common.EntityFrameworkCore.Extensions;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace AMWD.Common.EntityFrameworkCore.Attributes
|
|
{
|
|
/// <summary>
|
|
/// Property attribute to create indices and unique constraints in the database.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Requires <see cref="ModelBuilderExtensions.ApplyIndexAttributes(ModelBuilder)"/> to be called within <see cref="DbContext.OnModelCreating(ModelBuilder)"/>.
|
|
/// </remarks>
|
|
[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
|
|
public class DatabaseIndexAttribute : Attribute
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="DatabaseIndexAttribute"/> class.
|
|
/// </summary>
|
|
public DatabaseIndexAttribute()
|
|
{
|
|
Name = null;
|
|
IsUnique = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets a name.
|
|
/// </summary>
|
|
public string Name { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets a value indicating whether it is a unique constraint.
|
|
/// </summary>
|
|
public bool IsUnique { get; set; }
|
|
}
|
|
}
|