Thunder: Develop a custom module using an Entity Framework data provider
When using Entity Framework (EF) with Sitefinity CMS, Thunder generates all the files needed to plug-in EF into Sitefinity CMS. The custom module uses EF Code First approach. For more information, see https://msdn.microsoft.com/en-us/data/jj193542.aspx.
Once you have setup your module using the Custom module project template, you can add another or change the existing content types, while you are developing. Thunder creates all the new CRUD operations in the manager and the data provider. It adds all the new EF mappings and creates the new Master-detail views as Sitefinity CMS backend pages.
NOTE: If you change your mappings or your model, you must use EF Code First Migrations in order to apply the changes to the database. An alternative to the manual migrations are the Automatic Code First Migrations. It is up to you to decide which one to use.
The following example uses Automatic Code First Migrations with a custom module, named CustomModule1.
- After the custom module wizard finishes, you must enable Automatic Code First Migrations for your Custom Module Class Library Project in the following way:
- In Visual Studio open Tools » Library Package Manager » Package Manager Console.
- Inside that manager console select your default project to be CustomModule1.
- Execute the following command:
Enable-Migrations -EnableAutomaticMigrations - To update the database, execute the following command:
Update-Database -StartUpProjectName "CustomModule1" -ConnectionString "<your database connection string>" -ConnectionProviderName "System.Data.SqlClient" -Verbose
EF creates all the database tables that are current in your Code First model.
NOTE: If you want to change or to add a new entity to your model, using our Sitefinity CMS Custom Content Type item template, you must execute the Update-Database command above.
- Restart the IIS where your Sitefinity CMS application is running.
- You must manually uninstall and install your module.
With the new content type that you have created, Thunder has added new backend pages.
These pages are installed automatically when the module installs. Therefore, for the pages to appear in the main backend menu, you must reinstall the module.
To do this, perform procedure Activate and deactivate modules.