views:

121

answers:

1

This code works, but i dont understand why. With DeferredLoadingEnabld = false, I would expect it not to return the primary key. Can someone explain what I am missing?

public void SaveOrder (Order order)
{
        using (DataContext dc= new DataContext)
        {
           dc.DeferredLoadingEnabled = false;
           ...
           order.Total= total;
           dc.order.InsertOnSubmit(order);
           dc.SubmitChanges();
         }
}

IN ORDER SERVICE:

public void ServiceSaveOrder(Order order)
{     
    Order order= new Order();
    SaveOrder(order);
    Print(order.ID);  //ID= unique primary key
 }
+2  A: 

DeferredLoadingEnabled property is simply used for populating other relationships across foreign keys and not for returning IDs back after inserts. Your keys will always be populated. With DeferredLoadingEnabled set to true, any parent or child relationships will not automatically populated.

More information is available at the MSDN article.

Ray Booysen