Jeb746966
Jeb746966

Reputation: 107

How to override record table naming to access existing data in Orchard CMS

I need to access data from pre-existing tables. I've started working my way through creating a module to display the data etc. However, Orchard is prefixing the table commands with the 'Table_Prefix' and 'Module Name'.

Is there any way I can specify what table to bind the model, so that I can use the existing IRepository

I'm trying to steer clear of modifying the core code, or implement my own IRepository ( which I've got a feeling is what I'm going to have to do.)

Thanks in advance.

Upvotes: 3

Views: 927

Answers (2)

Bon
Bon

Reputation: 1

I was modifying CompositionStrategy and discovered that you have to modify the following

1. SetupService.cs (Modules\Orchard.Setup\Services):

Tables hardcoded in the Setup method are "Orchard_Framework_DataMigrationRecord" and "Settings_ShellDescriptorRecord"

2. InfosetController.cs (Modules\Upgrade\Controllers):

Multiple tables were hardcoded in this class which need to be updated.

3. DataMigrationManager.cs (Data\Migration):

Replace the SchemaBuilder parameters to the contructor.

Upvotes: 0

Piotr Szmyd
Piotr Szmyd

Reputation: 13366

You can create custom table naming convention (so that it would fit your current naming) by altering the core code, in three ways:

  1. Record name mapping is created in BuildRecord method of CompositionStrategy class (Orchard.Framework/Environment/ShellBuilders/CompositionStrategy), so you can simply modify the code here.
  2. By altering the Apply method of Orchard.Data.Conventions.RecordTableNameConvention class. This is where the record table name mappings (built in point 1.) get pushed to NHibernate.
  3. Create your own implementation of FluentNHibernate.Conventions.IClassConvention (similar to RecordTableNameConvention mentioned above and replace the default one used by AutoMap in Orchard.Data.Providers.AbstractDataServicesProvider's CreatePersistenceModel(...) method with it.

You could also create your own IDataServicesProvider implementation, but that would surely be an overkill if you only need to change the table naming convention.

Upvotes: 1

Related Questions