2009-09-16

Fluent NHibernate - Incorrect syntax near the keyword 'Group'

I have to share this. I spent a good amount of time searching around Fluent NHibernate for a way to escape columns in the generated SQL while still using AutoMapping.

My initial configuration looked like:


Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2005.ConnectionString(
c => c.Is(ConfigurationManager.ConnectionStrings["Something"].ConnectionString)))
.Mappings(x => x.AutoMappings.Add(AutoPersistenceModel.MapEntitiesFromAssemblyOf()
.WithSetup(convention =>
{
convention.FindIdentity = p => p.Name == p.DeclaringType.Name + "Id";
convention.GetComponentColumnPrefix = type => type.Name + "Id";
} )
.BuildSessionFactory()

This works great, but I had a property in my class (SomeType) that is called Group. This was causing the SqlException: Incorrect syntax near the keyword 'Group' (others would be like: Incorrect syntax near the keyword 'User' or Incorrect syntax near the keyword 'Table').

The solution I found was to use the Fluent NHibernate ConventionDiscovery + ConvensionBuilder to always add a column name possibility (to use in SQL) which would be escaped by [] for every property. Why not? This is SQL 2005 I'm working with, right?

So the final solution looked like:

Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2005.ConnectionString(
c => c.Is(ConfigurationManager.ConnectionStrings["Something"].ConnectionString)))
.Mappings(x => x.AutoMappings.Add(AutoPersistenceModel.MapEntitiesFromAssemblyOf()
.WithSetup(convention =>
{
convention.FindIdentity = p => p.Name == p.DeclaringType.Name + "Id";
convention.GetComponentColumnPrefix = type => type.Name + "Id";
} )
.ConventionDiscovery.Setup(c => c.Add(ConventionBuilder.Property.Always(
s => s.ColumnNames.Add("[" + s.Property.Name + "]"))))))
.BuildSessionFactory()

24 comments:

Obat Multikhasiat said...

Obat Tradisional Stroke Ringan Terbukti Ampuh
Pengobatan Tumor Otak paling Ampuh
Distributor Green World Mataram Nusa Tenggara Barat
Pantangan Makanan Bagi Penderita Nyeri Otot
Obat Lemah Syahwat paling Ampuh
Glucoberry dan Glucocoa untuk Menutrisi Kulit Sehat
Pengobatan Jantung Rematik secara Alami
Pusat Green World Bandung Jawa Barat
Pengobatan Alami untuk Meningkatkan Nafsu Makan Anak dan Dewasa
Tanaman Alami Herbal yang Dapat Mengobati Nyeri Lutut
Pengobatan Alami Rabun Jauh paling Ampuh
Obat Tradisional Diabetes yang paling Ampuh
Pengobatan Gagal Jantung secara Herbal
Distributor Green World Bandung Jawa Barat
Pengobatan Alami Memicu Penambah Tinggi Badan
Obat Tradisional Jantung Koroner paling Ampuh
Obat Serba Guna
Apotek Jelly Gamat Gold G
Obat Liver Alami
Obat Herbal Paru-Paru Basah Pada Anak
Obat Herbal Usus Buntu Kronis
Vig Power Capsule Harga
Agen Green World Indonesia
Terapi Obat Herbal

Herbal Ace Maxs said...

Nice article..
Thank you for sharing,
keep posting and update article or informatin more..
visit Khasiat Obat Ace Maxs

Obat Acemaxss said...

Thank you for sharing articles were very nice and useful like this ..
we liked it very much, I hope you can post or renew it again.
good luck,,
visit Obat Herbal Penyakit Leukemia

Elsa Permana said...

How do your activities today? hopefully smooth and fun
Thank you for sharing about the articles and information with us,,
we really liked and listened attentively ..
it is very nice
visit Obat Herbal Kanker Tulang

Obat Acemaxss said...

thank you for the information you present here,
Keep posting and I really like it.. it is very good
visit Obat Herbal Darah Tinggi

Elsa Permana said...

Thanks for sharing.. it is very good and amazing.
good job, gan. keep posting and sharing the article more
visit Obat Herbal Kanker Kelenjar Getah Bening

Obat Acemaxss said...

very good article and interesting, this may be the first step to your success.
Keep posting and updating information or other article,,
Thank you
visit Obat Benjolan Di Belakang Telinga Yang Ampuh

Herbal Ace Maxs said...

very nice article, interesting and easy to understand, this may be the first step to your success.
Keep posting and updating information or other article,,
Thank you
visit Obat Herbal Diabetes Melitus Yang Ampuh

Elsa Permana said...

I am not good at making information or a very good article, but this article makes me become motivated to make work better.
So, thank you for sharing the article very interesting and very good and this
visit Obat Benjolan Di Rahim Ampuh Dan Aman

Obat Acemaxss said...

Still listening article you serve to make me be inspired in makes work creating articles or information that could be useful,, interesting and easily understood.
Thank you very much for sharing and I wait for your next post.
survivors welcome the new year
visit Obat Herbal Gagal Ginjal Tanpa Cuci Darah

Herbal Ace Maxs said...

Very nice article guys,
simple, attractive and easy to understand it. You really do have a great reverensi and knowledge to make articles like this
good work and continue to share. Thank you for sharing with us
visit Obat Herbal Infeksi Saluran Kemih

Elsa Permana said...

My visit today on your website very pleasant ..
very nice article and the contents of the article are of sufficient quality.
hopefully more successful and hopefully this article can be useful for the visitors.
Thank you
visit | Obat Herbal Glaukoma Ampuh Dan Aman

Elsa Permana said...

This is article that you created and you have, very nice, the content easy to understand it and used as a reference of quality.
thank you for sharing.,, Keep posting and I wait for your next post
visit | Jenis Makanan Penyebab Hipertensi Pada Ibu Hamil

Obat Acemaxss said...

This article contains information that is very useful for all readers, especially my own. I wait for other information that is not less interesting
Thank you for sharing, Don't stop for the posting article or information more
visit | Kenali Penyebab Penyakit Stroke Dan Cara Mengatasinya

Elsa Permana said...

I find the article you created quite nice, charming, good words, and the contents of the article of sufficient quality.
Thank you for sharing the information pretty good. Continue to post another article
visit | Pengertian Penyakit Gagal Ginjal Akut Dan Kronis

Obat Acemaxss said...

I don't know how often I visit this blog..
But, thank you for sharing your article.. Keep posting
visit | Apakah Ginjal Bocor Bisa Sembuh Total

Herbal Ace Maxs said...

I found something in this article., a very nice design, the contents of the article were quite good and quality..
it is very suitable as a good reference.
Thank you very much for sharing with us
visit | Penyebab Ambeien Dan Cara Mengatasinya Tanpa Operasi

Elsa Permana said...

a very nice design, the contents of the article were quite good and quality..
it is very suitable as a good reference.
Thank you very much for sharing with us
visit | Waspadai Gejala Awal Glaukoma Penyebab Utama Kebutaan

Herbal Ace Maxs said...

I was very interested and like what is in this article, the content of the article is quite good and quality..
steady buildup gan. Thank you for sharing, gan
visit | 7 Makanan Yang Harus Di Hindari Oleh Penderita Stroke

Suraj Baba said...

Packers and Movers Hyderabad
Packers and Movers Bangalore
Packers and Movers Pune

Suraj Baba said...


Packers and Movers Mumbai
Packers and Movers Gurgaon
Packers and Movers Delhi

Suraj Baba said...

Packers and Movers Chennai
Packers and Movers Noida
Packers and Movers Navi Mumbai
Packers and Movers Thane
Packers and Movers Ghaziabad
Packers and Movers Faridabad

Suraj Baba said...



Packers and Movers in Hyderabad
Packers and Movers in Bangalore
Packers and Movers in Pune
Packers and Movers in Mumbai
Packers and Movers in Gurgaon
Packers and Movers in Delhi

obat kutil kelamin yang alami said...


I am often to blogging and i really appreciate your content. The article has really peaks my interest. I am going to bookmark your site and keep checking for new information.
oebta kencing nanah di jakarta utara
obat kencing nanah di tangerang
obat kencing nanah di bali
obat kutil di sekitar kemaluan dan dubur
cara sederhana mengobati penyakit kelamin
obat kutil kelamin di semarang
obat kutil kelamin di apotik
bagaimana cara menghilangkan kutil dengan cuka
apakah bisa mengobati kutil kelamin dengan bawang putih
Tanda-Tanda Kutil Kelamin Condyloma Acuminata