I am looking to use MvcScaffolding for a website that I already have a database for.
I am using the repository switch when scaffolding to create a repository per entity and then editing the file to use the entities rather than the MvcScaffolding context, obviously if I re generate the files then this change will be overwritten and I will have to fix all 80+ repositories!
So I have created a custom repository template using
Scaffold CustomTemplate repository repository
which I am looking to edit so that the repositories are generated correctly. I know I need to edit this line
<#= contextName #> context = new <#= contextName #>();
but I can't find which variable I should replace contextName
with.
I know I could easily hard code the model name in the repository file which I am about to do but wondered if there is a better way to do this?
The reason for wanting a way to do it programmatically is for scenarios where more than 1 EF model is used in a project and scaffolding is used for both.
Thanks
OneShot
There's a DbContextType
param for the scaffolders -
-DbContextType : Specify the name of the database context class that should be generated or updated. By default, we use the name Context, e.g., SoccerSiteContext.
Could you set that to be the name of the relevant model and avoid changing the template?