Let’s begin

There is still a lot of flaws in EntityFrameworkCore. Many of them is really irritating. That’s why first name of this library was EfCore.Irritation :).

EfCore.Shaman offers simple solution for some of problems.

Quick start – 3 steps to fix many problems

  1. Install nuget package
    Install-package EfCore.Shaman
  2. Enter following code in Up method in each Migration class:
    migrationBuilder.FixMigrationUp<YourDbConextClass>();
  3. Enter following code in OnModelCreating method in DbContext class:
    this.FixOnModelCreating(modelBuilder);

Columns order in table

Ef uses its own sorting method for columns in table. Primary key fields are first followed by other fields in alphabetical order. Neither natural properties order in ‘code first’ classes nor ColumnAttibute.Order  value is used for sorting.

To change this behaviour put code below at the end of protected override void Up(MigrationBuilder migrationBuilder)  method in each class derived from Migration.

migrationBuilder.FixMigrationUp<YourDbConextClass>();
New column order is based on natural properties order in ‘code first’ classes. This can be overrided by ColumnAttibute.Order  value.

Indexes

EfCore doesn’t support annotation for index creation. Each index definition must be in OnModelCreating  method in DbContext  class. It is inconsequence leading to worse code readablity.

EfCore.Shaman offers own IndexAttribute and UniqueIndexAttribute. In order to use this attributes put following code at the end of ‘ OnModelCreating ‘ method in you DbContext  class.

Index creation options

Simple one column index

Just use IndexAttribute and UniqueIndexAttribute without any parameter like below:

Own index name

Multi column indexes

To create index with more than one column put IndexAttribute or UniqueIndexAttribute with some name and number related to field position in in index

You can also use names starting with @ sign. That names will be replaced by name generated automatically by EF.

Descending field sorting

IndexAttribute and UniqueIndexAttribute contains bool IsDescending property designed for changing sorting order of index column. This is not yet supported.

Decimal columns precision

DecimalTypeAttribute  can be used for decorating decimal property. It affects changing decimal column type definition. For example

SqlServer support

In order to support SqlServer features add nuget package EfCore.Shaman.SqlServer and turn on necessary options in coniguration, i.e.

and

Collations specific to SqlServer is recognized by reflection scaner, i.e.

Moreover SqlServerCollationAttribute  can be used for class annotation in order to set default collation for all text columns (not supported yet).

Current release allows to specify column collation while only table is created.

Code signing

Assembly distributed with nuget package is signed with key.snk that is not included with github repository. mksnk.bat script file is included instead. It it running automatically during building process.

Plans

  • Full column collation support

Known bugs

  • Not supported descending field order in indexes