- SubSonic에 관계 (외래 키 또는 다른 방법들)에 대해 알려주는 방법은 무엇입니까?
만약 내가이 (예를 들어) 관련 팀 구성원 SubSonic에서 일대 다 관계를 사용하는 방법
**와 팀 객체 어떻게 팀** 어떻게 팀 구성원을 업데이트하나요에서 팀 구성원을 액세스하고 업데이트 할 수 있습니까? 팀 개체를 저장하면 팀원 변경 내용이 저장됩니까?
** 팀 구성원을 어떻게 추가합니까? 방금 새 회원을 만들고, 팀 ID를 외래 키에 할당하고 저장합니까? 아니면 더 객체 지향 방법 (예를 들어, team.Add (teamMember))
1
A
답변
3
음속 코드 생성이 테이블의 외래 키 관계를 읽고 테이블 클래스에서 필요한 도우미 메서드를 만듭니다가있다. Northwind Product 클래스에는 OrderDetail 클래스에 대한 PrimaryKey 관계가 있습니다. 음속이 방법을
공개 Northwind.OrderDetailCollection의 OrderDetails의 생성()
OrderDetailCollection로 OrderDetail 행 도착. 필요에 따라 변경할 수있는 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);
}
SubSonic에서 외래 키 관계가 유일한 방법입니까? 명명 규칙은 무엇입니까? – BuddyJoe