EfCore.Conventions 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package EfCore.Conventions --version 1.0.0
NuGet\Install-Package EfCore.Conventions -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EfCore.Conventions" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EfCore.Conventions --version 1.0.0
#r "nuget: EfCore.Conventions, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EfCore.Conventions as a Cake Addin
#addin nuget:?package=EfCore.Conventions&version=1.0.0

// Install EfCore.Conventions as a Cake Tool
#tool nuget:?package=EfCore.Conventions&version=1.0.0

Icon

EfCore.Conventions

Setting EF Core by conventions

Get it

PM> Install-Package EfCore.Conventions

Setting table names

For example, if you would like to pluralize all table names.

First, you need to get Inflector.

PM> Install-Package Inflector.NetStandard

Then add this to your data context file.

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    var inflector = new Inflector.Inflector(CultureInfo.GetCultureInfo("en-US"));
    modelBuilder.WithTableName(type => inflector.Pluralize(type.ClrType.Name));
}

Setting default column types

For example, if you would like to set all decimal to decimal(28, 2).

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.SetDefaultTypeNameForType<decimal>("decimal(28, 2)");
}

Custom action based on property type

For example, if you would like to set Conversion.

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.ForPropertyType<Employee>(builder => builder.HasConversion(new JsonConverter<Employee>()));
}

Custom action based on a predicate

For example, if you would like to set Conversion to all types annotated with NotMappedAttribute.

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.ForProperty(
        prop => prop.PropertyType.GetCustomAttribute<NotMappedAttribute>() != null,
        (builder, prop) => builder.HasConversion((ValueConverter)Activator.CreateInstance(typeof(JsonConverter<>).MakeGenericType(prop.PropertyType))));
}

Extended Attributes

EfCore.Conventions also comes with following extended attributes. If you would like to apply the attributes, you need to first set your modelBuilder.

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.WithExtendedAttributes();
}
CompositeKey

If you would like to add composite key, you can annotate with [CompositeKey].

For example.

public class OrderItem
{
    [CompositeKey]
    public string OrderId { get; set; }

    [CompositeKey]
    public int RunningNo { get; set; }

    ...
}

You can also annotated with [Column(Order = N)] to set column order.

Index

If you would like to set index to column, you can annotate with [Index].

For example,

public class User
{
    [Key]
    public string Id { get; set; }

    [Index]
    public string Email { get; set; }

    ...
}

You can also set composite and/or unique index.

public class Location
{
    [Index(Name = "IX_Zone_Area", Order = 1, IsUnique = true)]
    public string Zone { get; set; }

    [Index(Name = "IX_Zone_Area", Order = 2, IsUnique = true)]
    public string Area { get; set; }

    ...
}
OnDelete

You can set delete policy on column.

public class OrderItem
{
    public string SkuId { get; set; }

    [OnDelete(DeleteBehavior.Restrict)]
    public Sku Sku { get; set; }

    ...
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.2 489 9/28/2020
1.0.0 604 8/30/2019