4
我想知道EF CodeFirst是否會在下面的例子中自動跟蹤「子」對象。添加到父項時是否自動跟蹤子實體?
var db = MyDataContext();
var order = db.Orders.Find(orderId);
order.AddOrderLine("Fancy Product");
db.Commit();
這裏是我(簡化)域實體
public class OrderLine {
public Guid OrderLineId { get; private set; }
public Guid OrderId { get; private set; }
public string Description { get; private set; }
public OrderLine(Guid orderId, string description) {
OrderLineId = Guid.NewGuid();
OrderId = orderId;
Description = description;
}
}
public class Order : Aggregate {
public Guid OrderId { get; private set; }
public ICollection<OrderLine> OrderLines { get; private set; }
public void AddOrderLine(string description) {
OrderLines.Add(new OrderLine(OrderId, description));
}
}
@jessegavin:您對答案滿意嗎?還是您需要澄清? – 2011-03-22 22:45:37