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.
You can create custom table naming convention (so that it would fit your current naming) by altering the core code, in three ways:
- Record name mapping is created in
BuildRecord
method ofCompositionStrategy
class (Orchard.Framework/Environment/ShellBuilders/CompositionStrategy), so you can simply modify the code here. - By altering the
Apply
method ofOrchard.Data.Conventions.RecordTableNameConvention
class. This is where the record table name mappings (built in point 1.) get pushed to NHibernate. - Create your own implementation of
FluentNHibernate.Conventions.IClassConvention
(similar toRecordTableNameConvention
mentioned above and replace the default one used byAutoMap
inOrchard.Data.Providers.AbstractDataServicesProvider
'sCreatePersistenceModel(...)
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.
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.
精彩评论