.NET 3.5 的 Castle-ActiveRecord 教程已损坏?
有人尝试过使用 C# 3.5 的 ActiveRecord 介绍示例 吗? 不知怎的,我有一种感觉,这个样本完全错误或者已经过时了。 XML 配置完全错误:
<add key="connection.connection_string" value="xxx" />
应该是:(
<add key="hibernate.connection.connection_string" value="xxx" />
如果我正确理解 nhibernate 配置语法..)
我想知道我做错了什么。 在用户模型上调用 Count() 时,出现“无法对用户执行 ExecuteQuery”异常。
不知道这会是什么。 教程源代码与页面上的源代码有很大不同(最明显的是在 XML 配置中),并且它是一个 VS2003 示例,在大多数内容上具有不同的语法(没有泛型等)。
有什么建议么? ActiveRecord 看起来棒极了..
Has anyone tried the ActiveRecord Intro Sample with C# 3.5?
I somehow have the feeling that the sample is completely wrong or just out of date. The XML configuration is just plain wrong:
<add key="connection.connection_string" value="xxx" />
should be :
<add key="hibernate.connection.connection_string" value="xxx" />
(if I understand the nhibernate config syntax right..)
I am wondering what I'm doing wrong. I get a "Could not perform ExecuteQuery for User" Exception when calling Count() on the User Model.
No idea what this can be. The tutorial source differs strongly from the source on the page (most notably in the XML configuration), and it's a VS2003 sample with different syntax on most things (no generics etc).
Any suggestions? ActiveRecord looks awesome..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
(这对于评论帖子来说太长了)
[@Tigraine]从您对我之前的答案的评论来看,错误似乎不在于配置,而在于您的实体之一。 删除“hibernate”更正了配置,以便它给您带来真正的错误,这似乎是实体“Post”没有正确归属于 ActiveRecord 创建其映射。
如果您进一步查看它给出的错误,它可能有一些关于“发布”失败的详细信息。
一些常见的事情包括:
[ActiveRecord]
属性。[PrimaryKey]
属性的属性。PluralizeTableNames
为“true”,则为“Posts”)。虚拟
(这个总是让我丧命)。(This was too long for a comment post)
[@Tigraine] From your comments on my previous answer it looks like the error lies not with the configuration, but with one of your entities. Removing the "hibernate" corrected the configuration so that it geve you the real error, which appears to be that the entity "Post" is not properly attributed for ActiveRecord to create its mapping.
If you further down in the error that it gives, it likely has some details as to what about "Post" failed.
Some common things include:
[ActiveRecord]
attribute.[PrimaryKey]
attribute.PluralizeTableNames
is "true").virtual
(this one kills me all the time).NHibernate 2.0 版中删除了键的“hibernate”部分。
此版本对于 NHibernate 2.0 及以上版本是正确的:
编辑:
我发现快速入门没有附带 Castle 和 NHibernate 的二进制文件。 您必须从某个地方下载二进制文件; 如果您可以提供 NHibernate.dll 文件的版本号,将会很有帮助。
令人困惑的是,至少快速入门的一些内容已更新为最新的 NHibernate (NH) 2.0,但最新的“正确”Castle 版本仍然是 1.0 RC3(现在已经快一年了),其中不包括 NH 2.0。
你可以采取两种方式。 您可以继续使用 Castle RC3,在这种情况下,您确实需要将“hibernate”前缀添加到您的配置条目中。 或者您可以从主干下载 Castle 的版本,该版本应该针对 NH 2.0 运行。 后一种方法的问题在于 NH 2.0 中引入的一些其他重大更改可能无法在快速启动中修复。
The 'hibernate' portion of the key was removed in NHibernate version 2.0.
This version is correct for NHibernate 2.0 onwards:
Edit:
I see that the quickstart doesn't come with the binaries for Castle and NHibernate. You must have downloaded the binaries from somewhere; it would be helpful if you could provide the version number of your NHibernate.dll file.
Confusingly, at least SOME of the quickstart has been updated to be current with NHibernate (NH) 2.0, but the latest 'proper' Castle release is still the 1.0 RC3 (almost a year old now), which does not include NH 2.0.
You can go two ways. You can continue using Castle RC3 and in this case you will indeed need to add the 'hibernate' prefix to your configuration entries. Or you can download a build of Castle from the trunk, which should be running against NH 2.0. The problem with the latter approach is that some of the other breaking changes introduced in NH 2.0 might not be fixed in the quick start.
删除所有配置条目的“
hibernate.
”部分。 你的第一个例子是正确的。Delete the "
hibernate.
" part for all configuration entries. Your first example is the correct one.