Bad requests generated by NHibernate

Topics: Core
Aug 22, 2013 at 3:18 PM

I use in my Orchard the SQL Server CE 4.0 database (dev environment only - anywhere else SQL Server 2008 is used).

As you know, the tables created are prefixed by the module name. The problem is that my module name contains dashes (I can't change it, it's in our naming conventions) and NHibernate don't put brackets around table names in the generated requests wich leads to this exception :
[SQL: SELECT feedbackse0_.Id as Id65_0_, feedbackse0_.ContactEmailAddresses as ContactE2_65_0_ FROM VA-Tools-Feedback-IMPL-1_FeedbackSettingsRecord feedbackse0_ WHERE feedbackse0_.Id=?] ---> System.Data.SqlServerCe.SqlCeException: Une erreur s'est produite lors de l'analyse de la requête. [ Token line number = 1,Token line offset = 97,Token in error = - 
Is there a way to override record tables naming conventions or any other workaround ?

Aug 22, 2013 at 4:23 PM
One more crazy and unflexible naming convention, have seen to much of this..... :)
Can't you create a view in sql CE and get rid of this underscore in your module name ?
Aug 22, 2013 at 4:32 PM
Unfortunatly no ... The naiming conventions are defined by a client and as this is not the first module, changing the conventions would be quite complicated ...
Aug 22, 2013 at 5:06 PM
Edited Aug 22, 2013 at 5:07 PM
I would say your table naming convention is flawed, however!! if oyu want to do it... you could try this...

You will need to create a table convention.... i.e.
public class TableNameConvention
    : IClassConvention, IClassConventionAcceptance
    public void Accept(IAcceptanceCriteria<IClassInspector> criteria)
        criteria.Expect(x => x.TableName, Is.Not.Set);
    public void Apply(IClassInstance instance)
        instance.Table(instance.EntityType.Name.Replace("-", "_"));
And add that to the Fluent mapping....... check AbstractDataServicesProvider.cs
Aug 23, 2013 at 3:43 AM
Nick, good idea.
Since Orchard 1.7 there is a very easy way to modify NHibernate mappings with custom stuff - use ISessionConfigurationEvents. No need to alter the core.
Aug 23, 2013 at 7:27 AM
True True!.. didn't think about that extension point.
Aug 23, 2013 at 8:14 AM
Thanks you two.
We use Orchard 1.6.1, but i'll see with my client if we can uprgade to 1.7.
Aug 23, 2013 at 8:42 AM
If you cant update to 1.7, then modify the core... and make sure you comment what you do! :)

You might also be able to override the class in 1.6 using the OrchardSupressAttribute method. worth a go.