Git Product home page Git Product logo

efcore.shaman's Introduction

Intent

This is a personal project is a fork of the original efcoreshaman repository to resolve issues found in .Net Core 2.0.

Core.Shaman

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. For more information please visit http://efcoreshaman.com/.

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.

this.FixOnModelCreating(modelBuilder);

Index creation options

Simple one column index

Just use IndexAttribute and UniqueIndexAttribute without any parameter like below:

[Index]
public Guid InstanceUid { get; set; }

Own index name

[Index("MyName")]
public Guid InstanceUid { get; set; }

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

[Index("Idx_myName", 1)]
public Guid InstanceUid { get; set; }

[Index("Idx_myName", 2)]
public Guid BoxUid { get; set; }

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

[Index("@1", 1)]
public Guid InstanceUid { get; set; }

[Index("@1", 2)]
public Guid BoxUid { get; set; }

Descending field sorting

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

[Index("@1", 1)]
public Guid InstanceUid { get; set; }

[Index("@1", 2, true)]
public Guid BoxUid { get; set; }

Decimal columns precision

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

[DecimalType(18, 6)]
public decimal Amount { get; set; }

Specify Default values for columns

DefaultValueAttribute and DefaultValueSqlAttribute can be used for setting default values on columns. For example

[DefaultValue(true)]
public bool IsActive { get; set; }
[DefaultValueSql("getdate()")]
public DateTime DateCreated { get; set; }

SqlServer support

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

migrationBuilder.FixMigrationUp<YourDbConextClass>(ShamanOptions.Default.WithSqlServer());

and

this.FixOnModelCreating(modelBuilder, ShamanOptions.Default.WithSqlServer());

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

[SqlServerCollation(KnownCollations.Polish100CiAi)]
public string Code { get; set; }

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.

.NET Core version

Due to MsBuild issue csproj and packages.config can't coexist with xproj and project.json.

My own priority (sorry) is to maintain .Net framework version so files necessary for .NET Core compilation are provided in separate directory.

Plans

  • Full column collation support
  • .NetCore and .NetFramework release in the same time

Known bugs

  • Not supported descending field order in indexes

efcore.shaman's People

Contributors

isukces avatar borisdj avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.