开发者

accessing a table where the column name is a reserved keyword

开发者 https://www.devze.com 2023-01-11 09:05 出处:网络
I am setting up Castle Active Record to access a legacy database on an Microsoft SQL Server.The table in question has a column named function.When I 开发者_StackOverflowattampt to load a record it giv

I am setting up Castle Active Record to access a legacy database on an Microsoft SQL Server. The table in question has a column named function. When I 开发者_StackOverflowattampt to load a record it gives me this error:

Incorrect syntax near the keyword 'function'

This error comes about because the SQL query nhibernate generates attempts to access the column named function, which happens to be a restricted keyword. The fix is to wrap the column name in square braces ([function]) in the SQL statement. Is it possible to tell nhibernate to do this in its autogenerated SQL?


This will help you:

http://quomon.com/question-How-do-I-handle-database-reserved-words-in-NHibernate-1148.aspx

Example where table is a reserved keyword:

<class name="User" table="[user]" lazy="false">

I think the same applies for column names. Wrap them in square braces.

0

精彩评论

暂无评论...
验证码 换一张
取 消