.NET 3.5 的 Castle-ActiveRecord 教程已损坏?

发布于 2024-07-05 08:02:39 字数 639 浏览 10 评论 0原文

有人尝试过使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

千紇 2024-07-12 08:02:40

(这对于评论帖子来说太长了)

[@Tigraine]从您对我之前的答案的评论来看,错误似乎不在于配置,而在于您的实体之一。 删除“hibernate”更正了配置,以便它给您带来真正的错误,这似乎是实体“Post”没有正确归属于 ActiveRecord 创建其映射。

如果您进一步查看它给出的错误,它可能有一些关于“发布”失败的详细信息。

一些常见的事情包括:

  • 该类没有 [ActiveRecord] 属性。
  • 没有带有 [PrimaryKey] 属性的属性。
  • 没有名为“Post”的匹配表(如果 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:

  • THe class does not have the [ActiveRecord] attribute.
  • There is no property with the [PrimaryKey] attribute.
  • There is no matching table called "Post" (or "Posts" if PluralizeTableNames is "true").
  • There is no matching column(s) for attributed properties.
  • Your attributed properties and public methods are not virtual (this one kills me all the time).
北恋 2024-07-12 08:02:40

NHibernate 2.0 版中删除了键的“hibernate”部分。
此版本对于 NHibernate 2.0 及以上版本是正确的:

<add key="connection.connection_string" value="xxx" />

编辑:
我发现快速入门没有附带 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:

<add key="connection.connection_string" value="xxx" />

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.

七月上 2024-07-12 08:02:40

删除所有配置条目的“hibernate.”部分。 你的第一个例子是正确的。

Delete the "hibernate." part for all configuration entries. Your first example is the correct one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文