Parent and Child object in SimpleRepository

三世轮回 提交于 2019-12-05 14:34:34

I'm updating the SimpleRepo stuff currently to automatically create joined tables based on collections. Not easy to determine many/many vs 1/many - but I have some ideas :).

To create a one to many relationship you just have to create the object model, SubSonic should do the rest for you e.g.

public class Shop
{
  public int Id { get; set; }
  public String Name { get; set; }
  public List<Employee> Employees { get; set; }
}

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

EDIT: This should generate two tables when you run a migration not 3. The 3 three tables you describe in your question would represent a many to many relationship. Also in your example you're not saving your Employees, SubSonic does not cascade saves so you'll need to save your Shop then add the Employees to it and BatchSave the Employees.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!