Toolbelt.EntityFrameworkCore.IndexAttribute
1.0.1-beta
Revival of [Index] attribute for EF Core. (with extension for model building.)
[NOTICE] EF Core team said "We didn't bring this over from EF6.x because it had a lot of issues" (https://github.com/aspnet/EntityFrameworkCore/issues/4050)
You should consider well before use this package.
See the version list below for details.
Install-Package Toolbelt.EntityFrameworkCore.IndexAttribute -Version 1.0.1-beta
dotnet add package Toolbelt.EntityFrameworkCore.IndexAttribute --version 1.0.1-beta
<PackageReference Include="Toolbelt.EntityFrameworkCore.IndexAttribute" Version="1.0.1-beta" />
paket add Toolbelt.EntityFrameworkCore.IndexAttribute --version 1.0.1-beta
#r "nuget: Toolbelt.EntityFrameworkCore.IndexAttribute, 1.0.1-beta"
// Install Toolbelt.EntityFrameworkCore.IndexAttribute as a Cake Addin
#addin nuget:?package=Toolbelt.EntityFrameworkCore.IndexAttribute&version=1.0.1-beta&prerelease
// Install Toolbelt.EntityFrameworkCore.IndexAttribute as a Cake Tool
#tool nuget:?package=Toolbelt.EntityFrameworkCore.IndexAttribute&version=1.0.1-beta&prerelease
IndexAttribute for EntityFramework Core
What's this?
Revival of [Index]
attribute for EF Core. (with extension for model building.)
Attention
EF Core team said:
"We didn't bring this (= IndexAttribute) over from EF6.x because it had a lot of issues"
(https://github.com/aspnet/EntityFrameworkCore/issues/4050)
Therefore, you should consider well before use this package.
How to use?
- Annotate your model with
[Index]
attribute that lives inToolbelt.ComponentModel.DataAnnotations.Schema
namespace.
using Toolbelt.ComponentModel.DataAnnotations.Schema;
public class Person
{
public int Id { get; set; }
[Index] // <- Here!
public string Name { get; set; }
}
- [Important] Override
OnModelCreating()
method of your DbContext class, and callBuildIndexesFromAnnotations()
extension method which lives inToolbelt.ComponentModel.DataAnnotations
namespace.
using Microsoft.EntityFrameworkCore;
using Toolbelt.ComponentModel.DataAnnotations;
public class MyDbContext : DbContext
{
...
// Override "OnModelCreating", ...
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// .. and invoke "BuildIndexesFromAnnotations"!
modelBuilder.BuildIndexesFromAnnotations();
}
}
That's all!
BuildIndexesFromAnnotations()
extension method scans the DbContext with .NET Reflection technology, and detects [Index]
attributes, then build models related to indexing.
After doing that, the database which created by EF Core, contains indexes that are specified by [Index]
attributes.
For More Detail...
This library is designed to have the same syntax as EF 6.x [Index]
annotation.
Please visit document site of EF 6.x and [Index]
attribute for EF 6.x.
Not Supported Feature
IsClustered
property is not supported at this version.
License
IndexAttribute for EntityFramework Core
What's this?
Revival of [Index]
attribute for EF Core. (with extension for model building.)
Attention
EF Core team said:
"We didn't bring this (= IndexAttribute) over from EF6.x because it had a lot of issues"
(https://github.com/aspnet/EntityFrameworkCore/issues/4050)
Therefore, you should consider well before use this package.
How to use?
- Annotate your model with
[Index]
attribute that lives inToolbelt.ComponentModel.DataAnnotations.Schema
namespace.
using Toolbelt.ComponentModel.DataAnnotations.Schema;
public class Person
{
public int Id { get; set; }
[Index] // <- Here!
public string Name { get; set; }
}
- [Important] Override
OnModelCreating()
method of your DbContext class, and callBuildIndexesFromAnnotations()
extension method which lives inToolbelt.ComponentModel.DataAnnotations
namespace.
using Microsoft.EntityFrameworkCore;
using Toolbelt.ComponentModel.DataAnnotations;
public class MyDbContext : DbContext
{
...
// Override "OnModelCreating", ...
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// .. and invoke "BuildIndexesFromAnnotations"!
modelBuilder.BuildIndexesFromAnnotations();
}
}
That's all!
BuildIndexesFromAnnotations()
extension method scans the DbContext with .NET Reflection technology, and detects [Index]
attributes, then build models related to indexing.
After doing that, the database which created by EF Core, contains indexes that are specified by [Index]
attributes.
For More Detail...
This library is designed to have the same syntax as EF 6.x [Index]
annotation.
Please visit document site of EF 6.x and [Index]
attribute for EF 6.x.
Not Supported Feature
IsClustered
property is not supported at this version.
License
Release Notes
v.1.0.1
- Added support for Owned Entity Types.
v.1.0.0
- 1st release.
Dependencies
-
.NETStandard 2.0
- Microsoft.EntityFrameworkCore.Relational (>= 2.0.0)
Used By
NuGet packages (9)
Showing the top 5 NuGet packages that depend on Toolbelt.EntityFrameworkCore.IndexAttribute:
Package | Downloads |
---|---|
CoreMore
Package Description
|
|
Zny.DomainBase
实体基类
|
|
Zicard.API.Common
Bases microservices da Zicard API
|
|
Toolbelt.EntityFrameworkCore.IndexAttribute.SqlServer
The `[IndexColumn]` attribute that is the revival of `[Index]` attribute for EF Core. (with extension for model building.)
This package also provides [PrimaryKey] attribute.
|
|
Bnsights.Core
Package Description
|
GitHub repositories
This package is not used by any popular GitHub repositories.