This example shows how to pass in an ef object and add them to a transcation scope and loop for a set number of times until success or failure. The object is an order that has order details and payment info.

/// <summary>
/// Using EntityFramework
/// </summary>
/// <param name="order"></param>
/// <returns></returns>
public PushResults PushOrderTo(OrderHeader order)
{
/* * start trans
* add order
* add lines
* add payment(if there is one)
* close order
* return results */

int retries = 3;
bool success = false;
// string queueName = @".\Fulfilling";
PushResults pr = new PushResults();
pr.CustomerNumber = order.OESCustomerID;
pr.Message = "Start placing order in ";

if (IsOrderProcessed(order.OESOrderID) == false)
{
//Entities context = new Entities();
using (Entities context = new Entities())
{

for (int i = 0; i < retries; i++)
{
// Define a transaction scope for the operations.
using (TransactionScope transaction = new TransactionScope())
{
try
{
////add order
OrderMaster orderMaster = OrderHeader.CreateOrderRecord(order);

//// context.OrderMaster.AddObject(order);
context.AddToOrderMaster(orderMaster);


////add line items
foreach (OrderDetails oli in order.OrderLineItems)
{
context.AddToOrderLineItem(OrderDetails.CreateOrderLineRecord(oli));
}

//if order has payment(s) then add them
foreach (OrderPayments pi in order.OrderPayments)
{
context.AddToPaymentInfo(OrderPayments.CreatePaymentRecord(pi));
}

// Save changes pessimistically. This means that changes
// must be accepted manually once the transaction succeeds.
//context.SaveChanges(SaveOptions.DetectChangesBeforeSave);

context.SaveChanges();

//// Mark the transaction as complete.
transaction.Complete();
success = true;

break;

}
catch (Exception ex)
{
// Handle errors and deadlocks here and retry if needed.
// Allow an UpdateException to pass through and
// retry, otherwise stop the execution.
pr.Message = ex.Message ;
if (ex.GetType() != typeof(UpdateException))
{
Helper.ExceptionHandler.LogExceptionToDB(ex, "RNLUtilsws");
break;
}
// If we get to this point, the operation will be retried.

}

}
}

if (success)
{
// Reset the context since the operation succeeded.
context.AcceptAllChanges();
context.CloseMasterStructOrder(order.OESOrderID);
pr.IsSuccess = true;
pr.Message = "Order placed";
pr.CustomerNumber = order.OESCustomerID.ToString();
}
else
{
Console.WriteLine("The operation could not be completed in " + retries + " tries.");

}

// Dispose the object context.
//context.Dispose();
}

}
else
{
pr.IsSuccess = false;
pr.Message = "Order is closed";

}

return pr;
}