nhibernate 3.0 entity properties with spaces in the name

Posts   
 
    
SteveM
User
Posts: 22
Joined: 23-Mar-2011
# Posted on: 28-Apr-2011 18:10:29   

LLBLGen Pro 3.1 Final.

I am dealing with a legacy database that has numerous columns with spaces in the name. The legacy database has been ported to SQL Sever 2008. SQL Sever, LLBLGen, .Net (4.0) all have no problem with these names.

However, when NHibernate is generating SQL code, the queries fail because of these spaces. The names are not bracketed.

LLBLGen generates, for example, the following mapping code:

Map(x=>x.ActivtyTypeNam).CustomType("StringClob").Column("Activty TypeNam") .Access.CamelCaseField(Prefix.Underscore);

When I manually change that to:

Map(x=>x.ActivtyTypeNam).CustomType("StringClob").Column("[Activty TypeNam]") .Access.CamelCaseField(Prefix.Underscore);

(notice the square brackets) the queries work.

So, is there an LLBLGen setting that will automatically add those brackets for properties that have spaces (without changing something on each individual field - I have hundreds of them)?

Or, can you give me pointers on modifying the code generation templates to add the brackets whenever the '.Column()' method is used?

Thanks,

Steve

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 28-Apr-2011 22:14:46   

Sorry, this does indeed look like a bug. We'll correct it as soon as possible. In the meantime, you can edit the template yourself.

C:\Program Files (x86)\Solutions Design\LLBLGen Pro v3.1\Frameworks\NHibernate\Templates\Net3.5\C#\entityFluentMapping.lpt - can be edited in notepad, or opened in the LLBLGen designer to get syntax highlighting.

line 426 should look like this

sb.AppendFormat(".Column(\"{0}\")", targetField.FieldName);

Modify it as follows

sb.AppendFormat(".Column(\"[{0}]\")", targetField.FieldName);

Save and close the template, regenerate. This should get you going again.

Matt

SteveM
User
Posts: 22
Joined: 23-Mar-2011
# Posted on: 28-Apr-2011 22:51:17   

Yes, that fixes the problem. Thanks for the quick reply.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 29-Apr-2011 09:43:00   

That's not a fix for all database types though, it does fix it short term for sqlserver. We'll try to fix it today in a more generic way.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 29-Apr-2011 12:32:46   

Fixed in next build: - Column names weren't properly quoted with db specific surrounding quotes, so spaces etc. inside names were not escaped. - FluentNHibernate mappings now always generate .Column() statements to overcome the situation where the column name is equal to the field name but the DB is case sensitive - Discriminator column names were emitted after the entity field name, but it should have been the target column name.

(edit) the new build is now available on the website)

Frans Bouma | Lead developer LLBLGen Pro