SubSonic 3 - 简单存储库 - 一对多关系

发布于 2024-08-02 11:33:49 字数 547 浏览 5 评论 0原文

这是我第一次使用 Subsonic。

假设我有这些课程:

public class Store
{
    public int Id { get; set; }
    public String Name { get; set; }
}

public class Employee
{
    public int Id { get; set; }
    public String Name { get; set; }
}

一名员工与一家具有雇佣日期的商店相关。这意味着在数据库中我将​​有一个中间表,其中包含 StoreId、EmployeeId、StartDate、EndDate

UPDATE

员工可以从 2009-01-01 到 2009-04-04 为 StoreA 工作,从 2009-04-05 为 StoreB 工作......而且我不希望每次员工更换他工作的商店时我的数据表都会重复我的员工的所有信息。在这个例子中,员工只有一个名字,但假设一名员工有 10 项财产(地址、年龄、性别...)

我怎样才能实现这一点?

It's the first time I use Subsonic.

Let say I have those classes :

public class Store
{
    public int Id { get; set; }
    public String Name { get; set; }
}

public class Employee
{
    public int Id { get; set; }
    public String Name { get; set; }
}

An employee is related to a store with is hired date. This means that in the database I will have a middle table With StoreId, EmployeeId, StartDate, EndDate

UPDATE

An employee can work to the StoreA from 2009-01-01 to 2009-04-04 and work for StoreB from 2009-04-05 to ... And I don't want that my data table repeat all the information of my employee each time an employee change the store he working for. In this example employee have only a name, but lets say an employee got 10 property (adress, age, gender ...)

How could I achieve that ?

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

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

发布评论

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

评论(2

小…红帽 2024-08-09 11:33:49

根据您的评论和更新的问题,您似乎想要如下内容:

public class Store
{
    public int Id { get; set; }
    public String Name { get; set; }
}

public class StoreEmployee
{
    public int Id { get; set; }
    public Employee Employee { get; set; }
    public Store Store { get; set; }
    public DateTime HiredDate { get; set; }
}

public class Employee
{
    public int Id { get; set; }
    public String Name { get; set; }
}

Based on your comment and the updated question it looks like you want something like the following:

public class Store
{
    public int Id { get; set; }
    public String Name { get; set; }
}

public class StoreEmployee
{
    public int Id { get; set; }
    public Employee Employee { get; set; }
    public Store Store { get; set; }
    public DateTime HiredDate { get; set; }
}

public class Employee
{
    public int Id { get; set; }
    public String Name { get; set; }
}
少女七分熟 2024-08-09 11:33:49

您实际上需要一个多对多关系,它将员工记录连接到商店记录,并带有开始日期和结束日期的有效负载。

对象将如下所示:

public class Store
{
    public int Id { get; set; }
    public String Name { get; set; }
}

public class Employee
{
    public int Id { get; set; }
    public String Name { get; set; }
    public IList<EmploymentTerm> EmploymentTerms { get; set; }
}

public class EmploymentTerm
{
    public int Id { get; set; }
    public Store Store { get; set; }
    public Employee Employee { get; set; }
    public DateTime? StartDate { get; set; }
    public DateTime? EndDate { get; set; }
}

徒手完成此操作,因此可能会出现一些错误。

You'll actually need a many-to-many relationship which will join an Employee record to a Store Record, with a payload of Start and End Dates.

The Objects will look like this:

public class Store
{
    public int Id { get; set; }
    public String Name { get; set; }
}

public class Employee
{
    public int Id { get; set; }
    public String Name { get; set; }
    public IList<EmploymentTerm> EmploymentTerms { get; set; }
}

public class EmploymentTerm
{
    public int Id { get; set; }
    public Store Store { get; set; }
    public Employee Employee { get; set; }
    public DateTime? StartDate { get; set; }
    public DateTime? EndDate { get; set; }
}

Did this freehand so there could be a couple errors.

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