How to use one-to-many relationships in SubSonic

  • What are the ways to tell SubSonic about communication (only foreign keys or other methods)?
  • If I have (for example) a command object with related team members

    ** How can I access and update team members from the team.

    ** How do I update team members? Does the team object save the changes to team members.

    ** How to add participants to the team? Am I just creating a new member, assigning a team identifier to a foreign key and saving? Or there is a more object oriented way (e.g. team.Add (teamMember))

+1
source share
1 answer

. Northwind Product PrimaryKey OrderDetail. Subsonic

public Northwind.OrderDetailCollection OrderDetails()

OrderDetail OrderDetailCollection. BindingList, , SaveAll(), . , OrderDetail.

[Test]
public void Demo_Product_OrderDetails()
{
    Product product = new Product(3); // Read an existing row.
    OrderDetailCollection orderDetails = product.OrderDetails();
    Assert.IsTrue(orderDetails.Count == 12);
    foreach(OrderDetail orderDetail in orderDetails)
    {
        orderDetail.Discount -= 0; // Do something meaningful.
    }
    OrderDetail newDetail = new OrderDetail();
    newDetail.ProductID = 3;
    newDetail.OrderID = 10248;
    newDetail.UnitPrice = 7.00m;
    newDetail.Discount = 0.10f;
    newDetail.Quantity = 12;
    orderDetails.Add(newDetail);
    orderDetails.SaveAll();

    orderDetails = product.OrderDetails();
    Assert.IsTrue(orderDetails.Count == 13);

    OrderDetail.Destroy(newDetail.OrderID);

    orderDetails = product.OrderDetails();
    Assert.IsTrue(orderDetails.Count == 12);

}
+3

Source: https://habr.com/ru/post/1720565/


All Articles