Last active
March 13, 2019 07:30
-
-
Save TjeuKayim/ed8d28652b5936a2d289c3ff7ebf0e08 to your computer and use it in GitHub Desktop.
Workaround for 'Cannot combine -UseDataBaseNames with pluralizing' https://github.com/aspnet/EntityFrameworkCore/issues/12102
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.EntityFrameworkCore.Design; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.EntityFrameworkCore.Scaffolding.Internal; | |
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata; | |
// Scaffold-DbContext $db Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Context MyDbContext | |
namespace Database | |
{ | |
public class PluralizerServices : IDesignTimeServices | |
{ | |
public void ConfigureDesignTimeServices(IServiceCollection services) => services | |
.AddSingleton<IPluralizer, Pluralizer>() | |
.AddSingleton<ICandidateNamingService, CustomCandidateNamingService>(); | |
} | |
/// <summary> | |
/// Leave table and column names unmodified. | |
/// </summary> | |
public class CustomCandidateNamingService : CandidateNamingService | |
{ | |
public override string GenerateCandidateIdentifier(DatabaseTable originalTable) | |
{ | |
return originalTable.Name; | |
} | |
public override string GenerateCandidateIdentifier(DatabaseColumn originalColumn) | |
{ | |
return originalColumn.Name; | |
} | |
} | |
/// <summary> | |
/// Singularize names. | |
/// </summary> | |
public class Pluralizer : IPluralizer | |
{ | |
public string Pluralize(string name) | |
{ | |
return name; | |
} | |
public string Singularize(string name) | |
{ | |
if (name.EndsWith("sses")) | |
{ | |
return name.Remove(name.Length - 2); | |
} | |
if (name.EndsWith("s")) | |
{ | |
return name.Remove(name.Length - 1); | |
} | |
return name; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment