Skip to content

Commit

Permalink
Rename OverridePropertyNaming. Fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
pergerch committed Nov 27, 2018
1 parent 934af2a commit 85da380
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The two extension methods in the `OnModelCreating` method in the `DbContext` cla
- **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.
- **Singularize()** or **Pluralize()** defines whether the table names will be the singular or plural versions.
- **SetNamingScheme(...)** allows you to override the naming using one of the predefined schemes (see below) or a custom function.
- **OverrideTableNaming(...)**, **OverridePropertyNaming(...)**, **OverrideConstraintNaming(...)** to deviate from the general naming scheme.
- **OverrideTableNaming(...)**, **OverrideColumnNaming(...)**, **OverrideConstraintNaming(...)** to deviate from the general naming scheme.
- **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")`.
- **SkipTableNamingForGenericEntityTypes()** should be used to avoid naming the Enum lookup tables which can lead to unwanted results.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="EnumLockupAttribute.cs" company="Spatial Focus">
// <copyright file="EnumLookupAttribute.cs" company="Spatial Focus">
// Copyright (c) Spatial Focus. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// </copyright>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void ConfigureNames(this ModelBuilder modelBuilder, NamingOptions
// Properties
entity.GetProperties()
.ToList()
.ForEach(x => x.Relational().ColumnName = namingOptions.PropertyNamingFunction(x.Relational().ColumnName));
.ForEach(x => x.Relational().ColumnName = namingOptions.ColumnNamingFunction(x.Relational().ColumnName));

// Primary and Alternative keys
entity.GetKeys().ToList().ForEach(x => x.Relational().Name = namingOptions.ConstraintNamingFunction(x.Relational().Name));
Expand Down
19 changes: 9 additions & 10 deletions src/SpatialFocus.EntityFrameworkCore.Extensions/NamingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class NamingOptions

private Func<string, string> postProcessingTableNamingFunction = name => name;

private Func<string, string> propertyNamingFunction;
private Func<string, string> columnNamingFunction;

private Func<string, string> tableNamingFunction;

Expand All @@ -46,32 +46,31 @@ internal Func<IMutableEntityType, bool> EntitiesToSkipTableNaming

internal Func<string, string> NamingFunction { get; set; }

internal Func<string, string> PropertyNamingFunction
internal Func<string, string> ColumnNamingFunction
{
get => this.propertyNamingFunction ?? NamingFunction;
set => this.propertyNamingFunction = value;
get => this.columnNamingFunction ?? NamingFunction;
set => this.columnNamingFunction = value;
}

internal Func<IMutableEntityType, string> TableNameSource { get; set; }

internal Func<string, string> TableNamingFunction
{
get =>
name => this.postProcessingTableNamingFunction(this.tableNamingFunction != null
? this.tableNamingFunction(name)
name => this.postProcessingTableNamingFunction(this.tableNamingFunction != null ? this.tableNamingFunction(name)
: NamingFunction(name));
set => this.tableNamingFunction = value;
}

public NamingOptions OverrideConstraintNaming(Func<string, string> namingFunc)
public NamingOptions OverrideColumnNaming(Func<string, string> namingFunc)
{
ConstraintNamingFunction = namingFunc;
ColumnNamingFunction = namingFunc;
return this;
}

public NamingOptions OverridePropertyNaming(Func<string, string> namingFunc)
public NamingOptions OverrideConstraintNaming(Func<string, string> namingFunc)
{
PropertyNamingFunction = namingFunc;
ConstraintNamingFunction = namingFunc;
return this;
}

Expand Down

0 comments on commit 85da380

Please sign in to comment.