其他几个类持有的同一类的模型集合

发布于 2024-10-05 18:15:25 字数 579 浏览 1 评论 0原文

如何使用 Castle ActiveRecord 对以下内容进行建模?

我有两个类,客户和任务。

我想重用第三个类 Note,它存储在每个 Customer 和 Task 类的集合中。

public class Note
{
    public int ID { get; set; }
    public string Subject { get; set; }
    public string Body { get; set; }
}

public class Customer
{ 
    public int ID { get; set; }
    public IList<Note> Notes { get; set; }
}

public class Task
{
    public int ID { get; set; }
    public IList<Note> Notes { get; set; }
}

然后,我希望能够将 Notes 集合传递到 Customer 或 Task 类的相关 ASP.Net 页面中的 Gridview、Listview 或 Repeater。

How do I model the following using Castle ActiveRecord?

I have two classes, Customer and Task.

I would like to reuse a third class, Note, stored in a Collection in each of the Customer and Task classes.

public class Note
{
    public int ID { get; set; }
    public string Subject { get; set; }
    public string Body { get; set; }
}

public class Customer
{ 
    public int ID { get; set; }
    public IList<Note> Notes { get; set; }
}

public class Task
{
    public int ID { get; set; }
    public IList<Note> Notes { get; set; }
}

I would then like to be able to pass the Notes collection to a Gridview, Listview or Repeater in the relevant ASP.Net page for the Customer or Task classes.

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

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

发布评论

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

评论(2

未央 2024-10-12 18:15:25

我认为你需要的是实现类型层次结构。您可以在此处阅读相关内容。

I think what you need is to implement a type hierarchy. You can read about it here.

北凤男飞 2024-10-12 18:15:25

我们确定了以下模式:

[ActiveRecord]
public class Note
{
    [PrimaryKey]
    public int ID { get; set; }

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

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

    [BelongsTo]
    public Customer Customer { get; set; }

    [BelongsTo]
    public Customer Task{ get; set; }
}

[ActiveRecord]
public class Customer
{ 
    [PrimaryKey]
    public int ID { get; set; }

    [HasMany]
    public IList<Note> Notes { get; set; }
}

[ActiveRecord]
public class Task
{ 
    [PrimaryKey]
    public int ID { get; set; }

    [HasMany]
    public IList<Note> Notes { get; set; }
}

We settled on the following pattern:

[ActiveRecord]
public class Note
{
    [PrimaryKey]
    public int ID { get; set; }

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

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

    [BelongsTo]
    public Customer Customer { get; set; }

    [BelongsTo]
    public Customer Task{ get; set; }
}

[ActiveRecord]
public class Customer
{ 
    [PrimaryKey]
    public int ID { get; set; }

    [HasMany]
    public IList<Note> Notes { get; set; }
}

[ActiveRecord]
public class Task
{ 
    [PrimaryKey]
    public int ID { get; set; }

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