DB column called Order with Fluent NHibernate

I found that one of the tables of the old db that I am working on has a call called "Order". Unfortunately, I cannot change the structure of the database.
My Fluent NHibernate class looks like

public class SiteMap : AutoMap<Site> { public SiteMap() { WithTable("Sites"); Id(x => x.ID, "Id") .WithUnsavedValue(0) .GeneratedBy.Identity(); Map(x => x.Name, "Name"); //various columns mapping and then... Map(x => x.SiteOrder, "Order"); } } 

I do not know if the problems are FluentNH or NHibernate, but I can confirm that the problem is the reserved name "Order".

How to solve this?

Update: as intended by inserting the [Order] form. Thanks!
But now I am only associated with SQL2005?

+4
source share
2 answers

Try placing an order in reverse ticks: `` Order . Since FluentNH generates HBM files at runtime, I believe this should fix the problem.

+5
source

What kind of databases are behind the scenes?

With MS SQL, you can fix this by surrounding the Order field with square brackets

 Map(x => x.SiteOrder, "[Order]"); 

Edit: square brackets should work in all versions of MS SQL, as well as in MS Access. Not sure about other platforms, but it will probably work on some others as well.

+2
source

All Articles