EF core scaffolding di un database esistente

leo del ciello 66 Reputation points
2022-09-12T07:18:19.13+00:00

Sto facendo un programma che legge le estrazioni del Lotto dalle varie ruote .. Il database contiene tante tabelle quante sono le ruote, ognuna chiamata "Estrazione_"+ Nome ruota (es. "Estrazione_Roma", "Estrazione_Nazionale" etc..
Ho due problemi di cui uno particolarmente esilarante:

1) lo scaffolding mi pluralizza il nome del dbset: cioè a fronte della tabella "Estrazione_Roma" ho il modello "Estrazione_Roma" ma il dbset è "Estrazione_Romas" (con "s" finale ) : come faccio per evitare questa pluralizzazione ?

2) questo è davvero assurdo : la tabella dell'ultima ruota , "Estrazione_Venezia", viene resa nel modello "Estrazione_Venezium" (, si esattamente... desinenza "ium" che non so da dove venga ....) ... il dbset invece non è pluralizzato stavolta .... com'è possibile che EF "inventi" di sana pianta un nome modello che non esiste da nessuna parte ??????

il mio comando di scaffolding è il seguente:

Scaffold-DbContext “Data Source=LAPTOP-B0ND4A67;Initial Catalog=SmallLotto; Trusted_Connection=Yes;Encrypt=False  ” -Provider Microsoft.EntityFrameworkCore.SqlServer -Schema General -Context GeneralContext -OutputDir GeneralModels -UseDatabaseNames

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
697 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,235 questions
{count} votes

Accepted answer
  1. Jack J Jun 24,286 Reputation points Microsoft Vendor
    2022-09-13T08:38:39.08+00:00

    @leo del ciello , Welcome to Microsoft Q&A,

    - how to avoid pluralization of dbset names  
    - why only the table Venezia generates the entity Venezium and not Venezia  
    

    They are actually the same problem. We could use -NoPluralize command mentioned in doc to disable the pluralizer to solve the problem.

    Full command:

    Scaffold-DbContext 'connstr'  Microsoft.EntityFrameworkCore.SqlServer -NoPluralize  
    

    After run the command, you could see the following result:

    240521-image.png

    About your third question, Could you provide your database table design?

    Best Regards,
    Jack


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful