无法使用 Castle ActiveRecord 创建架构
我正在尝试开始使用 Castle ActiveRecord (遵循 "入门与 ActiveRecord” 截屏)。
我创建了两个 ActiveRecord 类,其中一个名为 User
。我将相关字符串添加到 app.config
文件中,并使用以下命令进行初始化:
var config = ActiveRecordSectionHandler.Instance;
ActiveRecordStarter.Initialize(typeof(User).Assembly, config);
ActiveRecordStarter.CreateSchema();
不幸的是,当我运行此命令时,出现以下异常:
未处理的异常: Castle.ActiveRecord.Framework.ActiveRecordException: 无法创建架构 ---> NHibernate.HibernateException: 关键字附近的语法不正确 '用户'。 ---> System.Data.SqlClient.SqlException: 关键字附近的语法不正确 “用户”
我将一个小复制品上传到 http://bitbucket.org/hmemcpy/general,可以有人请告诉我我做错了什么吗?
谢谢!
I'm trying to get started with Castle ActiveRecord (following the "Getting started with ActiveRecord" screencast).
I created two ActiveRecord classes, one of them named User
. I added the relevant strings to the app.config
file, and I initialize using:
var config = ActiveRecordSectionHandler.Instance;
ActiveRecordStarter.Initialize(typeof(User).Assembly, config);
ActiveRecordStarter.CreateSchema();
Unfortunately, when I run this, I get the following exception:
Unhandled Exception:
Castle.ActiveRecord.Framework.ActiveRecordException:
Could not create the schema --->
NHibernate.HibernateException:
Incorrect syntax near the keyword
'User'. --->
System.Data.SqlClient.SqlException:
Incorrect syntax near the keyword
'User'
I uploaded a small reproduction to http://bitbucket.org/hmemcpy/general, could someone please tell me what have I done wrong?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
'User'是SQL Server中的保留字,执行的SQL命令是:
在SQL Server中将表命名为User是非法的,但将其命名为[User]< /em>。
作为解决方案,您可以为由保留字命名的表和列定义不同的名称:
当在表名称周围使用 [ ] 时,允许保留名称。这同样适用于关系列:
当然,任何其他名称,如
[ActiveRecord("SomeUser")]
都可以。'User' is a reserved word in SQL server, the SQL command being executed is:
It's illegal to name a table User in SQL server, but it is legal to name it [User].
As a solution you can define different names for tables and columns named by reserved words:
When using a [ ] around the table name, reserved names are allowed. The same is relevant for relation columns:
Of course, any other name like
[ActiveRecord("SomeUser")]
will work.