Subsonic 亚音速3-简单存储库-一对多关系
这是我第一次使用亚音速 假设我有这些课程:Subsonic 亚音速3-简单存储库-一对多关系,subsonic,subsonic3,one-to-many,Subsonic,Subsonic3,One To Many,这是我第一次使用亚音速 假设我有这些课程: 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; } } 员工与雇佣日期为的商店有关联。这意味着在数据库中,我将有一个中间表,其中包含S
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
更新
员工可以在2009-01-01至2009-04-04期间为StoreA工作,在2009-04-05至2009-04-04期间为StoreB工作。。。我不希望每次员工更改他工作的商店时,我的数据表都重复我员工的所有信息。在这个例子中,雇员只有一个名字,但假设一个雇员有10个财产(地址、年龄、性别…)
我怎样才能做到这一点呢?根据您的评论和更新后的问题,您似乎想要以下内容:
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; }
}
根据您的评论和更新的问题,您似乎需要以下内容:
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; }
}
实际上,您需要一个多对多关系,将员工记录连接到商店记录,有效负载为开始日期和结束日期 对象将如下所示:
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; }
}
公共类存储
{
公共int Id{get;set;}
公共字符串名称{get;set;}
}
公营雇员
{
公共int Id{get;set;}
公共字符串名称{get;set;}
公共IList EmploymentTerms{get;set;}
}
公共类雇用期限
{
公共int Id{get;set;}
公共存储{get;set;}
公共雇员雇员{get;set;}
公共日期时间?开始日期{get;set;}
公共日期时间?结束日期{get;set;}
}
这样做是徒手的,所以可能会有一些错误 实际上,您需要一个多对多关系,将员工记录连接到商店记录,有效负载为开始日期和结束日期 对象将如下所示:
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; }
}
公共类存储
{
公共int Id{get;set;}
公共字符串名称{get;set;}
}
公营雇员
{
公共int Id{get;set;}
公共字符串名称{get;set;}
公共IList EmploymentTerms{get;set;}
}
公共类雇用期限
{
公共int Id{get;set;}
公共存储{get;set;}
公共雇员雇员{get;set;}
公共日期时间?开始日期{get;set;}
公共日期时间?结束日期{get;set;}
}
这样做是徒手的,所以可能会有一些错误 也许我表达错了。我的意思是,员工可以在2009-01-01至2009-04-04期间为StoreA工作,在2009-04-05至2009-04-04期间为StoreB工作。。。我不希望每次员工更改他工作的商店时,我的数据表都重复我员工的所有信息。在这个例子中,雇员只有一个名字,但假设一个雇员得到了10个财产(地址、年龄、性别……),也许我表达错误了。我的意思是,员工可以在2009-01-01至2009-04-04期间为StoreA工作,在2009-04-05至2009-04-04期间为StoreB工作。。。我不希望每次员工更改他工作的商店时,我的数据表都重复我员工的所有信息。在这个例子中,雇员只有一个名字,但假设一个雇员有10个财产(地址、年龄、性别…)