Skip to content

Commit cc4d1dc

Browse files
committed
Update README.md
1 parent ddf7f25 commit cc4d1dc

File tree

1 file changed

+58
-2
lines changed

1 file changed

+58
-2
lines changed

README.md

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,74 @@
11
# SpatialFocus.EntityFrameworkCore.Extensions
2+
23
A set of useful extensions for EntityFrameworkCore (Enum Lookup Tables, Naming of tables / properties / keys, Pluralize).
34

45
[![Build Status](https://spatial-focus.visualstudio.com/EntityFrameworkCore.Extensions/_apis/build/status/EntityFrameworkCore.Extensions-CI)](https://spatial-focus.visualstudio.com/EntityFrameworkCore.Extensions/_build/latest?definitionId=3)
56
[![NuGet](https://img.shields.io/nuget/v/SpatialFocus.EntityFrameworkCore.Extensions.svg)](https://www.nuget.org/packages/SpatialFocus.EntityFrameworkCore.Extensions/)
67

78
## Installation
89

9-
```
10+
```console
1011
Install-Package SpatialFocus.EntityFrameworkCore.Extensions -Version 1.0.0-rc2
1112
```
1213

1314
## Usage
1415

15-
For an example usage, see the `DemoContext` in the [sample project](https://github.com/SpatialFocus/SpatialFocus.EntityFrameworkCore.Extensions/tree/master/samples/SpatialFocus.EntityFrameworkCore.Extensions.SQLiteDemo) for now.
16+
This extension provides two extension methods to modify the `modelBuilder` in the `OnModelCreating` method in the `DbContext` class.
17+
18+
```csharp
19+
using SpatialFocus.EntityFrameworkCore.Extensions;
20+
21+
public partial class MyContext : DbContext
22+
{
23+
// ...
24+
25+
protected override void OnModelCreating(ModelBuilder modelBuilder)
26+
{
27+
modelBuilder.ConfigureEnumLookup(EnumLookupOptions.Default.UseStringAsIdentifier());
28+
29+
modelBuilder.ConfigureNames(NamingOptions.Default.SkipTableNamingForGenericEntityTypes());
30+
31+
// ...
32+
}
33+
}
34+
```
35+
36+
## Configuration Options
37+
38+
The two extension methods in the `OnModelCreating` method in the `DbContext` class:
39+
40+
- **ConfigureEnumLookup(...)** allows you to define in which form lookup tables for *Enums* will be constructed and named:
41+
42+
- **Default** defines the naming scheme for the table to use *snake_case* and to use the number lookup format.
43+
- **UseNumberAsIdentifier()** or **UseStringAsIdentifier()** defines whether the lookup table will be based on the string enum values or the numeric enum value as primary key in the resulting table and as foreign key in the relation.
44+
- **Singularize()** or **Pluralize()** defines whether the table names will be the singular or plural versions of the enum type.
45+
- **SetNamingScheme(...)** allows you to override the naming using one of the predefined schemes (see below) or a custom function.
46+
47+
- **ConfigureNames(...)** allows you to define in which form tables, properties and constraints will be named:
48+
49+
- **Default** defines the naming scheme for the elemens to use *snake_case* for naming and the *DbSet name* to name the tables.
50+
- **SetTableNamingSource(...)** defines which naming source to use (see below). It means whether to use the ClrType name or the DbSet name to name the tables.
51+
- **Singularize()** or **Pluralize()** defines whether the table names will be the singular or plural versions.
52+
- **SetNamingScheme(...)** allows you to override the naming using one of the predefined schemes (see below) or a custom function.
53+
- **OverrideTableNaming(...)**, **OverridePropertyNaming(...)**, **OverrideConstraintNaming(...)** to deviate from the general naming scheme.
54+
- **SkipEntireEntities(...)** and **SkipTableNamingForEntities(...)** to skip the naming for either the whole entity or just the table name for certain entities by using a `Func<IMutableEntityType, bool>` skip function, e.g. `SkipEntireEntities(entity => entity.Name == "MyEntity")`.
55+
- **SkipTableNamingForGenericEntityTypes()** should be used to avoid naming the Enum lookup tables which can lead to unwanted results.
56+
57+
### Naming Schemes
58+
59+
- NamingScheme.SnakeCase
60+
- NamingScheme.ScreamingSnakeCase
61+
- NamingScheme.KebabCase
62+
- Any custom `Func<string, string>`, e.g. `SetNamingScheme(name => name.ToLower())`
63+
64+
#### Naming Source
65+
66+
- NamingSource.ClrType
67+
- NamingSource.DbSet
68+
69+
## Examples
70+
71+
For an exemplary usage, see the `DemoContext` in the [sample project](https://github.com/SpatialFocus/SpatialFocus.EntityFrameworkCore.Extensions/tree/master/samples/SpatialFocus.EntityFrameworkCore.Extensions.SQLiteDemo).
1672

1773
----
1874

0 commit comments

Comments
 (0)