Reserved words not auto-mapped

fe1337's Avatar

fe1337

14 Mar, 2010 08:19 PM via web

Hello,

It appears like the latest version 1.0 RTM is not mapping the reserved words properly. For example I have a field "Order" and I get an error back from NHibernate about it. Looking at the generated xml file here is the culprit:


<column name="Order" />

With my limited knowledge of NHibernate I believe this field should be surrounded by `?

Thanks.

  1. 2 Posted by fe1337 on 14 Mar, 2010 11:31 PM

    fe1337's Avatar

    Just FYI, I also have the same problems with fields named "From" and "To".

  2. Support Staff 3 Posted by Paul Batum on 15 Mar, 2010 11:28 AM

    Paul Batum's Avatar

    You should try downloading one of the more recent builds.

    https://fluentnhibernate.org/downloads

  3. 4 Posted by fe1337 on 15 Mar, 2010 01:36 PM

    fe1337's Avatar

    I got build #632 and that didn't help, I have the same problem.

  4. Support Staff 5 Posted by James Gregory on 17 Mar, 2010 10:38 AM

    James Gregory's Avatar

    We don't auto-quote column names because not all database dialects/drivers in NHibernate support it. You need to do this yourself.

    There are several options, firstly you could use the hbm2ddl.keywords setting if your database supports it. Secondly, you could create a convention (probably an IColumnConvention) to change the name of the columns and quote them yourself. You've not said whether you're using automapping or not, if you aren't there's also the option of specifying the columns explicitly in your mappings.

  5. 6 Posted by fe1337 on 17 Mar, 2010 09:40 PM

    fe1337's Avatar

    I'm using automapping. I will have a look at your suggestions. I'm surprised that Paul's answer seemed to acknowledge an issue by advising me to download the latest version, while you're saying that this is in fact normal behavior.

    Thanks.

  6. Support Staff 7 Posted by Paul Batum on 17 Mar, 2010 10:51 PM

    Paul Batum's Avatar

    Basically there's been ALOT of changes since the RTM, including some aspects of auto-quote behavior. It can be pretty difficult to remember how the RTM is behaving so as a rule when someone starts a support request with "I'm on the RTM and..." I will tell them to get a later build - if they still have an issue after doing that, assisting them will be all the easier once we know they have the latest changes.

    Sorry if you felt like I misled you.

  7. 8 Posted by Joseph LeBlanc on 12 Apr, 2010 06:26 PM

    Joseph LeBlanc's Avatar

    I'm having the exact same issue. Can someone post an esample of how to use IColumnConvention? I can't seem to figure it out and can't find any examples anywhere.

  8. 9 Posted by Joseph LeBlanc on 13 Apr, 2010 05:00 PM

    Joseph LeBlanc's Avatar

    I figured it out.

    public class EscapeReservedSqlKeywordsInColumnNamesConvention : IPropertyConvention
    {
        private List<string> keywords = new List<string>() { "ADD","EXISTS","PRECISION","ALL","EXIT","PRIMARY","ALTER","EXTERNAL","PRINT","AND","FETCH","PROC","ANY","FILE","PROCEDURE","AS","FILLFACTOR","PUBLIC","ASC","FOR","RAISERROR","AUTHORIZATION","FOREIGN",
                    "READ","BACKUP","FREETEXT","READTEXT","BEGIN","FREETEXTTABLE","RECONFIGURE","BETWEEN","FROM","REFERENCES","BREAK","FULL","REPLICATION","BROWSE","FUNCTION","RESTORE","BULK","GOTO","RESTRICT",
                    "BY","GRANT","RETURN","CASCADE","GROUP","REVERT","CASE","HAVING","REVOKE","CHECK","HOLDLOCK","RIGHT","CHECKPOINT","IDENTITY","ROLLBACK","CLOSE","IDENTITY_INSERT","ROWCOUNT","CLUSTERED","IDENTITYCOL",
                    "ROWGUIDCOL","COALESCE","IF","RULE","COLLATE","IN","SAVE","COLUMN","INDEX","SCHEMA","COMMIT","INNER","SECURITYAUDIT","COMPUTE","INSERT","SELECT","CONSTRAINT","INTERSECT","SESSION_USER","CONTAINS","INTO",
                    "SET","CONTAINSTABLE","IS","SETUSER","CONTINUE","JOIN","SHUTDOWN","CONVERT","KEY","SOME","CREATE","KILL","STATISTICS","CROSS","LEFT","SYSTEM_USER","CURRENT","LIKE","TABLE","CURRENT_DATE","LINENO","TABLESAMPLE",
                    "CURRENT_TIME","LOAD","TEXTSIZE","CURRENT_TIMESTAMP","MERGE","THEN","CURRENT_USER","NATIONAL","TO","CURSOR","NOCHECK","TOP","DATABASE","NONCLUSTERED","TRAN","DBCC","NOT","TRANSACTION","DEALLOCATE","NULL",
                    "TRIGGER","DECLARE","NULLIF","TRUNCATE","DEFAULT","OF","TSEQUAL","DELETE","OFF","UNION","DENY","OFFSETS","UNIQUE","DESC","ON","UNPIVOT","DISK","OPEN","UPDATE","DISTINCT","OPENDATASOURCE","UPDATETEXT",
                    "DISTRIBUTED","OPENQUERY","USE","DOUBLE","OPENROWSET","USER","DROP","OPENXML","VALUES","DUMP","OPTION","VARYING","ELSE","OR","VIEW","END","ORDER","WAITFOR","ERRLVL","OUTER","WHEN","ESCAPE","OVER","WHERE","EXCEPT",
                    "PERCENT","WHILE","EXEC","PIVOT","WITH","EXECUTE","PLAN","WRITETEXT" };
    
        #region IConvention<IPropertyInspector,IPropertyInstance> Members
    
        public void Apply(IPropertyInstance instance)
        {
            if (keywords.Contains(instance.Name.ToUpper()) == true)
            {
                instance.Column(string.Format("[{0}]",instance.Name));
            }
        }
    
        #endregion
    }
    
  9. Paul Batum resolved this discussion on 25 Apr, 2010 01:54 PM.

Comments are currently closed for this discussion. You can start a new one.