EfCore.Conventions
1.0.0
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
<PackageReference Include="EfCore.Conventions" Version="1.0.0" />
<PackageVersion Include="EfCore.Conventions" Version="1.0.0" />
<PackageReference Include="EfCore.Conventions" />
paket add EfCore.Conventions --version 1.0.0
#r "nuget: EfCore.Conventions, 1.0.0"
#addin nuget:?package=EfCore.Conventions&version=1.0.0
#tool nuget:?package=EfCore.Conventions&version=1.0.0
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 | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.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. |
-
.NETStandard 2.0
- Microsoft.EntityFrameworkCore (>= 2.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 2.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.