Note that there are some explanatory texts on larger screens.

plurals
  1. POLINQ to SQL - Insert yielding strange behavior
    primarykey
    data
    text
    <p>I'm trying to insert several newly created items to the database. I have a LINQ2SQL generated class called "Order".</p> <p>Inside order, there's a property called "OrderItems" which is also generated by LINQ2SQL and represents the Items of that Order.</p> <p>So far so good. The problem I'm having right now, is when I try to add more than one newly created OrderItem inside Order.</p> <p>I.E:</p> <pre><code>Order o = orderWorker.GetById( 10 ); for( int i=0; i &lt; 5; ++i ) { OrderItem oi =new OrderItem { Order = o, Price = 100, ShippingPrice = 100, ShippingMethod = ..., Item = someItem }; o.OrderItems.Add( oi ); } context.SubmitChanges(); </code></pre> <p>Unfortunately, only a single entity is being added. Yes, I checked the generated SQL by adding Context.Log = Console.Out, and yes, only one statement was created.</p> <p>Any clues? By the way I know I'm not using InsertOnSubmit, by the documentation says:</p> <blockquote> <p>You can explicitly request Inserts by using InsertOnSubmit. Alternatively, LINQ to SQL can infer Inserts by finding objects connected to one of the known objects that must be updated. For example, if you add an Untracked object to an EntitySet(TEntity) or set an EntityRef(TEntity) to an Untracked object, you make the Untracked object reachable by way of tracked objects in the graph. While processing SubmitChanges, LINQ to SQL traverses the tracked objects and discovers any reachable persistent objects that are not tracked. Such objects are candidates for insertion into the database.</p> </blockquote> <p>Thank you very much for your time.</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. 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