How to override record table naming to access existing data in Orchard CMS - asp.net

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 of
CompositionStrategy class
(Orchard.Framework/Environment/ShellBuilders/CompositionStrategy), so you can simply modify the code here.
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.
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.

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.

Related

Is there a way to programmatically create folders?

Is there a way to programmatically create folders? There was a way to do it in lotus script - that method also was not documented in designer help. I want to get a document collection and then put the whole collection into a folder. I can see in the documentation that this will create the folder - I want to add columns to the folder. I suppose at worst I can open the folder after it has been created from the "put" command.
You can use ViewEntryCollection.PutAllInFolder method https://www.ibm.com/support/knowledgecenter/en/SSVRGU_9.0.1/basic/H_PUTALLINFOLDER_METHOD_VEC_JAVA.html
The folder will be created from the view/folder flagged as "Default for new views/folders" property. To change its design, you can use createColumn method https://www.ibm.com/support/knowledgecenter/SSVRGU_9.0.0/com.ibm.designer.domino.main.doc/H_CREATECOLUMN_METHOD_VIEW_JAVA.html
If you want to modify the design by adding columns, it will need to run with a ID that has at least Designer access to the database. ODA has a design API that can be used to create design elements via DXL. I've used it to create views, but folders should work the same.
If you don't need to modify the design, you can create a Shared Private on First Use folder by running as the user and calling getView(). I don't think that needs designer access, but it's worth double-checking.
Note: the ODA methods haven't been tested from SSJS. If it works, you're lucky, but the focus is Java.

2sxc List.Presentation in General View

I have an entity type "Post" and I would like to create a view that will show one random Post with a given category. I created a Data pipeline that grabs all posts and I created a view with ListPresentation = a "TemplateSettings" entity type that lets me choose categories.
I planned to use the Razor template to filter the items for those matching the categories in List.Presentation.Categories. But, I can't seem to reference List.Presentation.Categories. I get an error that System.Collections.Generic.List doesn't contain an entry for "Presentation". When I use #ListPresentation, the whole object in null... so #ListPresentation.Toolbar, etc. all throw errors, despite me having set a "Demo Item".
Can anybody see what would be wrong with this setup? How do I reference List Presentation stuff in Razor?
Thanks.
I figured this out... The direct thing seems to be "ListPresentation", but the snippets use "List.Presentation". Still, it wasn't working in my case because I was using a data query that didn't include the module data. So, I had to modify that query to include the module data as well as the full list of entities, regardless of the module. Then, I got the full list from one data stream, and the ListPresentation fields were available.
Note also that you can use ListContent.Presentation - that would be the newest, most consistent API which always places Presentation information as a property of the entity it's describing.

Generating dictionary from a directory (for Lucene autocomplete)

Using Lucene 4.9 (Java), I've been looking for a way to implement an autocomplete/suggest feature. The goal is to use several of the fields data used in my indexed documents as the source of the dictionary. What is the best practice or suggested way of generating a dictionary based on this?
I tried LuceneDirectory, but the issue is that it only accepts one field, shown below:
LuceneDictionary ld = new LuceneDictionary(indexReader, "fieldname");
What i'm looking for is something similar to this, but with a possibility of being able to supply an array of string with fields to populate my dictionary.
My next step was to look at the source of the class of LuceneDirectory, hoping to make my own custom Dictionary class implementing the Lucene directory interface. This however, was outside of my scope, and I was hoping someone else might have already done an implementation of this, or know how I can proceed.
To summarize:
1: How do I create a dictionary from an existing directory, with data from multiple fields(terms)?
2: How do I keep the dictionary updated once it has been created? Should I regenerate it on a regular basis or are there any other best practices for this?
You can add multiple Dictionaries to a SpellChecker, like:
SpellChecker spellchecker = new SpellChecker(spellIndexDirectory);
spellchecker.indexDictionary(new LuceneDictionary(indexReader, "fieldname"));
spellchecker.indexDictionary(new LuceneDictionary(indexReader, "anotherfield"));

Entity Framework for Multi-tenant architecture - filterings single table by tenant ID

We are looking for a way of automatically filtering all CRUD operations by a tenant ID in Entity Framework.
The ideas we thought of were:
Using table valued user defined functions
Using stored procedures (but we don't really want to, as we're using an ORM to avoid doing so)
Some how modifying the templates used to generate the SQL to add a where clause on each statement.
Some how modifying the templates used to generate the LINQ in the controllers (we may use MVC).
Any tips?
-thanks
Alex.
Using table valued user defined functions
Table valued function are only available in .NET 4.5 Beta (and not available in code first). Using them will still not help you because you will have to use the function in every LINQ query so it is the same as using where clause.
Using stored procedures (but we don't really want to, as we're using an ORM to avoid doing so)
It can be useful for some special complex queries but generally it is not what you want.
Some how modifying the templates used to generate the SQL to add a where clause on each statement.
Too complex and on completely different level of abstraction.
Some how modifying the templates used to generate the LINQ in the controllers (we may use MVC).
Close to ideal solution. You simply need to wrap access to your entity set into some code which will look like:
public class MultiTenantAccess<T> where T : IMultitenant
{
private IDbSet<T> set;
...
public IQueryable<T> GetQuery(int tenantID)
{
return set.Where(e => e.TenantID == tenantID);
}
}
Sometimes this is core for something called Generic repository but it is really just a wrapper around EF set. You will always use GetQuery to query your data store instead of using DbSet directly.
you may also separate the tenants data into different databases
or into same database, but with different schemas? You can read more about this in an old MSDN article called "Multi-Tenant Data Architecture"

How do I exclude the Scheme name from SqlMetal generated Objects?

SqlMetal is creating object names such as...
The View:
Sales.ProductDescription
is created as:
Sales_ProductDescription
Ideally SqlMetal would create the ProductDescription class under a namespace .Sales. but thats probably too much to ask for. So is there anyways to get it to create the class without the sheme prefix such as "ProductDescription".
Thanks,
Justin
This would involve some modifications to the DBML file after it's been generated. However, in terms of maintainability that might restrict your ability to quickly regenerate when the schema changes.
If you have a volatile schema you could check out this collection of powershell scripts I wrote some time ago that will handle such changes to the DBML. It takes an XML file as input. Warning: the sample in the code repository may be out of date, but the scripts certainly work - I still use them.
SqlMetal has an optional parameter to include a namespace. The default value is no namespace. Check out this link on MSDN.
http://msdn.microsoft.com/en-us/library/bb386987.aspx

Resources