Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't know if the following is a solution for you but Entity Framework supports <a href="https://stackoverflow.com/a/762994/270591">Identifying Relationships</a>. In such a relationship the foreign key of the child entity (dependent) to the parent (principal) must be part of the (composite) primary key of the child entity. For example - with <code>DbContext</code> data annotations - your model classes have to look like this:</p> <pre><code>public class Order { [Key] public int OrderId { get; set; } public ICollection&lt;OrderLine&gt; OrderLines { get; set; } } public class OrderLine { [Key, ForeignKey("Order"), Column(Order = 1)] public int OrderId { get; set; } [Key, Column(Order = 2)] public int OrderLineId { get; set; } public Order Order { get; set; } } </code></pre> <p>You can make the <code>OrderLineId</code> an autogenerated identity if you want. Important is only that the FK to <code>Order</code> is part of the PK.</p> <p>A code like this for example...</p> <pre><code>using (var ctx = new MyContext()) { var order = ctx.Orders.Include("OrderLines").Single(o =&gt; o.OrderId == 1); var orderLineToDelete = order.OrderLines .FirstOrDefault(ol =&gt; ol.OrderLineId == 5); if (orderLineToDelete != null) order.OrderLines.Remove(orderLineToDelete); ctx.SaveChanges(); } </code></pre> <p>...would indeed <em>delete</em> the <code>orderLineToDelete</code> from the database.</p> <p>More details are <a href="http://msdn.microsoft.com/en-us/library/ee373856.aspx" rel="nofollow noreferrer">here</a> in section "<em>Considerations for Identifying and Non-identifying Relationships</em>".</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload