Castle ActiveRecord 加入

发布于 2024-11-16 02:03:12 字数 913 浏览 3 评论 0原文

我是 Castle ActiveRecord 新用户,现在我发现有必要执行涉及 JOIN 的选择。我不知道该怎么做。

这是我的两个(示例)类:

[ActiveRecord("Orders")]
public class Order : ActiveRecordBase<Order>
{
   [PrimaryKey(PrimaryKeyType.Identity)]
    public int OrderID { get; set; }

    [Property]
    public int UserID { get; set; }

    [Property]
    public DateTime OrderDate { get; set; }

    [Property]
    public string ShipName { get; set; }

}

[ActiveRecord("Users")]
public class UserAccount : ActiveRecordBase<UserAccount>
{
    [PrimaryKey(PrimaryKeyType.Identity)]
    public int UserID { get; set; }

    [Property]
    public string FirstName { get; set; }

    [Property]
    public string LastName { get; set; }

}

现在,如果我想获取所有订单以及 UserAccount.FirstName 和 UserAccount.LastName,我该怎么做?根据我的阅读,我需要创建另一个类,如“OrdersWithUserAccount”,但我不知道如何定义它。

感谢您帮助菜鸟!

I'm a new Castle ActiveRecord user, and I now find it necessary to do a select that involves a JOIN. I have no idea how to do so.

Here's my two (sample) classes:

[ActiveRecord("Orders")]
public class Order : ActiveRecordBase<Order>
{
   [PrimaryKey(PrimaryKeyType.Identity)]
    public int OrderID { get; set; }

    [Property]
    public int UserID { get; set; }

    [Property]
    public DateTime OrderDate { get; set; }

    [Property]
    public string ShipName { get; set; }

}

[ActiveRecord("Users")]
public class UserAccount : ActiveRecordBase<UserAccount>
{
    [PrimaryKey(PrimaryKeyType.Identity)]
    public int UserID { get; set; }

    [Property]
    public string FirstName { get; set; }

    [Property]
    public string LastName { get; set; }

}

Now if I want to get all orders, along with the UserAccount.FirstName and UserAccount.LastName, how do I do it? By my reading, I need to create another class like "OrdersWithUserAccount" but I have no idea how to define it.

Thanks for helping out a noob!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

淡淡離愁欲言轉身 2024-11-23 02:03:12

您是否已完成Castle ActiveRecord 教程

我注意到的一件事是,您没有对象关系,而是关键关系。要按照 NHibernate 和 Castle ActiveRecord 的预期方式使用它们,您的对象模型应该具有对象之间的关系。

这意味着您的 Order 类应该有一个 User 属性,该属性指向 UserAccount 的实例。您的 UserAccount 类应该有一个 Orders 集合。根据我的经验,这通常应该是一个 ISet,您可以在 UserAccount 构造函数中将其初始化为 HashedSet

Have you gone through the Castle ActiveRecord tutorial?

One thing I notice is that you don't have object relations, but key relations. To use NHibernate and Castle ActiveRecord the way they're intended, your object model should have relationships betweeen objects.

This means that your Order class should have a User property which points to an instance of a UserAccount. Your UserAccount class should have an Orders collection. In my experience, this should usually be an ISet<Order>, which you initialize in the UserAccount constructor as a HashedSet<Order>.

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