-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plural DbContext names, singular tables? #15
Comments
@bricelam I know we occasionally mention pluralization but I don't have a good picture of this... Does pluralization/singularization belong in a naming conventions plugin like this one? |
We don’t do it at runtime in the product because fixing any pluralization bugs would be a breaking change. We have plans to do it at design time for reverse engineering. IMHO, it’s totally fine in an extension like this where the bar for breaking changes is a lot lower. But, just removing the convention that uses the DbSet name as the table name would be enough for this issue, right? |
I think the idea is that a convention is still desired, just that it inflects for table names as .net prescribes plural |
I agree singularization should be OK in this extension, anyone know of a good singularizer? |
The Roslyn team uses https://github.com/Humanizr/Humanizer for name reccomendations |
But wouldn't doing dotnet/efcore#11160 light up with this extension? |
I had to use |
Do we have any progress? |
Not at the moment, there's too many other things going on. I can try to review a PR though. |
Hold on a moment. Am I the only one who just wants the name of the tables to reflect the name of the type rather than that of some singularized form of a plural name which most of the time is already a pluralized form of the type? So you have a entity called Shouldn't we just add an option to use the type name as naming: |
@macshack I think you have things confused - this extension (EFCore.NamingConventions) just changes the casing of identifiers (e.g. PascalCase to snake-case), it does not do any plural->singular transformations (or vice versa). This specific issue is asking for this extension to do singularization (but it does not currently do that). As for EF itself, as @bricelam noted above, no pluralization/singularization is done at runtime. So I think things already work as you want? |
You can easily remove the pluralization convention in EF Core 7 onward with the following. // In your DbContext
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
configurationBuilder.Conventions.Remove(typeof(TableNameFromDbSetConvention));
}
|
Will that make the table names singular, or just result in an error as a result of them not being explicitly specified per-model? |
@atrauzzi EF Core doesn't need the "TableNameFromDbSetConvention" convention to name tables. If that convention is removed it will use the name of the class if the [Table] attribute has not been applied to it. I use the technique I mentioned in projects where I have a mixture of EF Core 7+ and Dapper for example. |
@jeremycook Your suggestion did work in my case. Thank you! |
@jeremycook is that possible to use your solution with EF Core 6? The ModelConfigurationBuilder.Conventions property is not available there, and I can't find any way to access it. |
@buden It looks like I misspoke about it being available in EF Core 6. Looking at that version of the API, I also don't see the |
IMHO good practice for DB design is to name tables in plural form, e.g. if your entity is called |
@kalatchev - The active record pattern messes around with inflectors (gooses or geese?) and adds complexity while offering no benefit. When you say "the active record pattern", you're likely referring to Rails ActiveRecord which is just one implementation. It's down to perspective and to be honest, I'm not arguing the point you make. More the conclusion you come to as a result as your argument is really more of a bias around one specific circumstance. For example, if I'm writing a query, I could also argue that when I'm referencing a table, it's more logical to have non-plural names in conditions: Either way, the more important point above is that having an inflector be part of my database logic is not desirable and that the plural forms of names tend to introduce more complexity. Whether for machines, or even for people (English not a first language, something I deal with daily). |
Note: this breaks when using TPC, the concrete tables generated are still pluralized leading to inconsistency IMHO a table is the entity type (singular) while the set of tuples is the entity set (plural). I really hope we will finally get a simple way to reliably override this default. |
As the title says, I think one convention that might be worth having as a toggle is to inflect singular table names from plural
DbContext
properties.🙂
The text was updated successfully, but these errors were encountered: