SimpleRepository 中的父对象和子对象
如果我希望能够在对象之间建立一对多的关系,那么在 Subsonic 的 SimpleReporitory 中它将如何工作?
我是否必须创建一个桥接对象,然后在运行时构建我的父对象,还是内置了此支持?
我正在寻找的是以下内容:
Adam 的示例商店...
Public Class Shop Private m_id As Integer Private m_Name As String Private m_Employees As List(Of Employee) Public Property Id() As Integer Get Return m_id End Get Set(ByVal value As Integer) m_id = value End Set End Property Public Property Name() As String Get Return m_Name End Get Set(ByVal value As String) m_Name = value End Set End Property Public Property Employees() As List(Of Employee) Get Return m_Employees End Get Set(ByVal value As List(Of Employee)) m_Employees = value End Set End Property End Class Public Class Employee Private m_id As Integer Private m_Name As String Public Property Id() As Integer Get Return m_id End Get Set(ByVal value As Integer) m_id = value End Set End Property Public Property Name() As String Get Return m_Name End Get Set(ByVal value As String) m_Name = value End Set End Property End Class
主要内容:
Dim repo As New SimpleRepository("SubSonicObjectTest", SimpleRepositoryOptions.RunMigrations) Dim emplyee1 As New Employee emplyee1.Name = "Martin" Dim emplyee2 As New Employee emplyee2.Name = "Adam" Dim shop As New Shop shop.Name = "Sub Sonic Store" shop.Employees = New List(Of Employee) shop.Employees.Add(emplyee1) shop.Employees.Add(emplyee2) repo.Add(Of Shop)(shop)
我认为这应该创建 3 个表:
商店
员工
ShopsToEmployees(或其他一些命名约定)
但我只得到一个 Channels 表!
How would it work in Subsonic's SimpleReporitory if I wanted to be able to have a 1 to many relationship between objects?
Would I have to create a bridge object and then build my parent object at runtime, or is this support built in?
What I am looking for is the folowing:
Adam's Example Shop...
Public Class Shop Private m_id As Integer Private m_Name As String Private m_Employees As List(Of Employee) Public Property Id() As Integer Get Return m_id End Get Set(ByVal value As Integer) m_id = value End Set End Property Public Property Name() As String Get Return m_Name End Get Set(ByVal value As String) m_Name = value End Set End Property Public Property Employees() As List(Of Employee) Get Return m_Employees End Get Set(ByVal value As List(Of Employee)) m_Employees = value End Set End Property End Class Public Class Employee Private m_id As Integer Private m_Name As String Public Property Id() As Integer Get Return m_id End Get Set(ByVal value As Integer) m_id = value End Set End Property Public Property Name() As String Get Return m_Name End Get Set(ByVal value As String) m_Name = value End Set End Property End Class
Main bits:
Dim repo As New SimpleRepository("SubSonicObjectTest", SimpleRepositoryOptions.RunMigrations) Dim emplyee1 As New Employee emplyee1.Name = "Martin" Dim emplyee2 As New Employee emplyee2.Name = "Adam" Dim shop As New Shop shop.Name = "Sub Sonic Store" shop.Employees = New List(Of Employee) shop.Employees.Add(emplyee1) shop.Employees.Add(emplyee2) repo.Add(Of Shop)(shop)
I think this should create 3 tables:
Shops
Employees
ShopsToEmployees (or some other naming convention)
But I only get a Channels table!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我当前正在更新 SimpleRepo 内容,以根据集合自动创建连接表。确定多/多与 1/多并不容易 - 但我有一些想法:)。
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 :).
要创建一对多关系,您只需创建对象模型,SubSonic 应该为您完成其余的工作,例如
编辑:当您运行迁移时,这应该生成两个表而不是 3。您在问题中描述的 3 个三个表将代表多对多的关系。另外,在您的示例中,您没有保存您的员工,SubSonic 不会级联保存,因此您需要保存您的商店,然后将员工添加到其中并批量保存员工。
To create a one to many relationship you just have to create the object model, SubSonic should do the rest for you e.g.
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.